Skip to content

Instantly share code, notes, and snippets.

@codepaladin
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codepaladin/04e7c8ed2fa73fcb8a65 to your computer and use it in GitHub Desktop.
Save codepaladin/04e7c8ed2fa73fcb8a65 to your computer and use it in GitHub Desktop.
-- 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