Difference between revisions of "TileMap"
From GiderosMobile
(added example) |
(added example) |
||
Line 27: | Line 27: | ||
tilew, tileh -- display width and height | tilew, tileh -- display width and height | ||
) | ) | ||
− | -- | + | -- build the map |
for i=1,4 do | for i=1,4 do | ||
for j=1,4 do | for j=1,4 do | ||
Line 33: | Line 33: | ||
end | end | ||
end | end | ||
− | -- some other tiles in the | + | -- some other tiles in the map |
tm:setTile(6,3,5,1) -- col position, row position, tile col index in tilemap, tile row index in tilemap | tm:setTile(6,3,5,1) -- col position, row position, tile col index in tilemap, tile row index in tilemap | ||
tm:setTile(7,3,5,1) -- col position, row position, tile col index in tilemap, tile row index in tilemap | tm:setTile(7,3,5,1) -- col position, row position, tile col index in tilemap, tile row index in tilemap | ||
tm:setTile(6,4,5,2) -- col position, row position, tile col index in tilemap, tile row index in tilemap | tm:setTile(6,4,5,2) -- col position, row position, tile col index in tilemap, tile row index in tilemap | ||
tm:setTile(7,4,5,3) -- col position, row position, tile col index in tilemap, tile row index in tilemap | tm:setTile(7,4,5,3) -- col position, row position, tile col index in tilemap, tile row index in tilemap | ||
− | -- position the | + | -- position the map and add to stage |
tm:setPosition(0, 0) | tm:setPosition(0, 0) | ||
stage:addChild(tm) | stage:addChild(tm) |
Revision as of 00:06, 8 March 2020
Supported platforms:
Available since: Gideros 2011.6
Inherits from: Sprite
Description
The TileMap class is used to work with tile maps easily and efficiently.
Check Desert and Sewers examples provided with Gideros for usage of TileMap with export from editor.
Example
-- set the tilemap texture
local texture = Texture.new("gfx/finalts16.png")
-- number of columns and rows in the tileset
local tilesetcols, tilesetrows = 11, 5
-- calculate the tiles width and height
local tilew, tileh = texture:getWidth() / tilesetcols, texture:getHeight() / tilesetrows
-- create the tilemap
local tm = TileMap.new(
2*16, 2*8, -- map size in tiles
texture, -- tileset texture
tilew, tileh, -- tile size in pixel
0, 0, -- spacing
0, 0, -- margin
tilew, tileh -- display width and height
)
-- build the map
for i=1,4 do
for j=1,4 do
tm:setTile(i, j, i, j)
end
end
-- some other tiles in the map
tm:setTile(6,3,5,1) -- col position, row position, tile col index in tilemap, tile row index in tilemap
tm:setTile(7,3,5,1) -- col position, row position, tile col index in tilemap, tile row index in tilemap
tm:setTile(6,4,5,2) -- col position, row position, tile col index in tilemap, tile row index in tilemap
tm:setTile(7,4,5,3) -- col position, row position, tile col index in tilemap, tile row index in tilemap
-- position the map and add to stage
tm:setPosition(0, 0)
stage:addChild(tm)
MethodsTileMap.new creates a new TileMap instance |
EventsConstantsTileMap.FLIP_DIAGONAL |