I am trying to draw a grid of white lines on a sprite. Depending on the grid cell size, every third line is drawn white, every third gray, and every third even more gray. What am I doing wrong here?
It seems to work fine with cell size of 30, 60, 90, ... so multiples of 30 and some others as well.. Many other sizes give me a grid such as attached image.
#constant GRID_CELL_W 20
demo()
function demo()
SetErrorMode(2)
SetOrientationAllowed( 0, 0, 1, 1 )
SetWindowTitle( "gridtest" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
devW# = 1920
devH# = 1080
SetVirtualResolution( devW#, devH# )
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
lb# = GetScreenBoundsLeft()
alb# = abs(lb#)
tb# = GetScreenBoundsTop()
atb# = abs(tb#)
screenW = devW# + alb#*2
screenH = devH# + atb#*2
img_id = CreateRenderImage(screenW, screenH,0,0)
SetRenderToImage(img_id,0)
ClearScreen()
cols = screenW/GRID_CELL_W
rows = screenH/GRID_CELL_W
x1 = lb#
x2 = screenW
y1 = tb#+GRID_CELL_W/2
y2 = y1
for r = 0 to rows
DrawLine(x1, y1, x2, y2, 255, 255, 255)
inc y1, GRID_CELL_W
inc y2, GRID_CELL_W
next r
x1 = lb#+GRID_CELL_W/2
x2 = x1
y1 = tb#
y2 = screenH
for c = 0 to cols
DrawLine(x1, y1, x2, y2, 255, 255, 255)
inc x1, GRID_CELL_W
inc x2, GRID_CELL_W
next c
SetRenderToScreen()
sid = CreateSprite(img_id)
SetSpriteSize(sid, screenW, screenH)
SetSpriteDepth(sid, 1000)
SetSpritePosition(sid, lb#, tb#)
SetSpriteVisible(sid, TRUE)
do
sync()
loop
endfunction