Hi all,
I’ve got the code below that creates a grid of tiles near the top left corner of the screen. What I’d like to do is have the grid centered on the screen regardless of the board width and height - this will be selectable by the user.
I’m not brilliant at maths and when I’ve tried to work out how to do it it hasn’t worked and usually either ends up in the wrong place or just a mess in the centre at which point my brain starts shouting at me to admit defeat and ask for help. So here we are. This is the code I have for creating the grid so far…
display.setDefault( "background", .80, .90, .80 ) local boardWidth = 10 local boardHeight = 10 local board = {} local function createBoard () local vOffset = 1 for r = 1, boardHeight do local hOffset = 1 board[r]={} for c = 1, boardWidth do local x = (24\*c)+hOffset local y = ((24\*r)+vOffset) board[r][c] = display.newRect( x, y, 23, 23 ) board[r][c]:setFillColor(.4, .4, .5, 1) board[r][c].strokeWidth = 1 ; board[r][c]:setStrokeColor(0,0,0) hOffset = hOffset + 2 end vOffset = vOffset + 2 end end createBoard()
Pleeeease help save my brain and tell me it’s really easy.