Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- draw a tile map to the screen
-- populate the tile map
function drawGrid()
for row = 0, 5 do
local gridRow = {}
for col = 0, 5 do
-- draw a diamond shaped tile
local vertices = { 0,-16, -64,16, 0,48, 64,16 }
local tile = display.newPolygon(group, 0, 0, vertices )
-- outline the tile and make it transparent
tile.strokeWidth = 1
tile:setStrokeColor( 0, 1, 1 )
tile.alpha = .25
-- set the tile's x and y coordinates
local x = col * tileHeight
local y = row * tileHeight
tile.x = x - y
-- the first part of this equation is to move the y coordinate down 32 pixels (tileHeight/2)
tile.y = (tileHeight/2) + ((x + y)/2)
-- make a tile walkable
gridRow[col] = 0
end
-- add gridRow table to the map table
map[row] = gridRow
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment