To best use the functions defineTile() should be placed in love.load and drawTiles() in love.draw pass through same values for w, h on each function
Code: Select all
tileGrid = {
tile = {},
defineTile = function(w, h)
sw, sh = love.window.getMode()
tileWidth = sw/w
tileHeight = sh/h
num = 0
for j = 0, h-1 do
for i = 0, w-1 do
num = num + 1
table.insert(tileGrid.tile, num, {tileWidth * i, tileHeight * j, false})
end
end
return tileWidth, tileHeight
end,
drawTile = function(w, h)
sw, sh = love.window.getMode()
tileWidth = sw/w
tileHeight = sh/h
num = 0
for j = 0, h-1 do
for i = 0, w-1 do
num = num + 1
love.graphics.setColor(i/w, j/h, 1)
rect = {
love.graphics.rectangle("line", tileWidth * i, tileHeight * j, tileWidth, tileHeight),
love.graphics.print(num, tileWidth * i, tileHeight * j)
}
end
end
end
}