Difference between revisions of "TileMap"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
<!-- GIDEROSOBJ:TileMap -->
 
<!-- GIDEROSOBJ:TileMap -->
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
+
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Sprite|Sprite]]<br/>
+
'''Inherits from:''' [[Sprite]]<br/>
=== <translate>Description</translate> ===
+
 
<translate><br />
+
=== Description ===
The [[Special:MyLanguage/TileMap|TileMap]] class is used to work with tile maps easily and efficiently.<br />
+
The '''TileMap''' class is used to work with tile maps easily and efficiently.
<br />
+
 
Check ''Desert'' and ''Sewers'' examples provided with Gideros for usage of TileMap with export from editor</translate>
+
Check ''Desert'' and ''Sewers'' examples provided with Gideros for usage of TileMap with export from editor.
 +
 
 +
=== Example ===
 +
<syntaxhighlight lang="lua">
 +
-- 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)
 +
</syntaxhighlight>
 +
 
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Methods</translate> ===
+
=== Methods ===
[[Special:MyLanguage/TileMap.new|TileMap.new]] ''<translate>creates a new TileMap instance</translate>''<br/><!-- GIDEROSMTD:TileMap.new -->
+
[[TileMap.new]] ''creates a new TileMap instance''<br/><!--GIDEROSMTD:TileMap.new(width,height,texture,tilewidth,tileheight,spacingx,spacingy,marginx,marginy,displaywidth,displayheight) creates a new TileMap instance-->
[[Special:MyLanguage/TileMap:clearTile|TileMap:clearTile]] ''<translate>set an empty tile at given indices</translate>''<br/><!-- GIDEROSMTD:TileMap:clearTile -->
+
[[TileMap:clearTile]] ''sets an empty tile at given indices''<br/><!--GIDEROSMTD:TileMap:clearTile(x,y) sets an empty tile at given indices-->
[[Special:MyLanguage/TileMap:getTile|TileMap:getTile]] ''<translate>returns the index of the tile</translate>''<br/><!-- GIDEROSMTD:TileMap:getTile -->
+
[[TileMap:getTile]] ''returns the index of the tile''<br/><!--GIDEROSMTD:TileMap:getTile(x,y) returns the index of the tile-->
[[Special:MyLanguage/TileMap:setRepeat|TileMap:setRepeat]] ''<translate>Indicate if the tilemap should repeat itself</translate>''<br/><!-- GIDEROSMTD:TileMap:setRepeat -->
+
[[TileMap:setRepeat]] ''indicates if the tilemap should repeat itself''<br/><!--GIDEROSMTD:TileMap:setRepeat(x,y) indicates if the tilemap should repeat itself-->
[[Special:MyLanguage/TileMap:setTexture|TileMap:setTexture]] ''<translate>Change the tile texture/atlas used by the tilemap</translate>''<br/><!-- GIDEROSMTD:TileMap:setTexture -->
+
[[TileMap:setTexture]] ''changes the tile texture/atlas used by the tilemap''<br/><!--GIDEROSMTD:TileMap:setTexture(texture,tilewidth,tileheight,spacingx,spacingy,marginx,marginy) changes the tile texture/atlas used by the tilemap-->
[[Special:MyLanguage/TileMap:setTile|TileMap:setTile]] ''<translate>sets the index of the tile</translate>''<br/><!-- GIDEROSMTD:TileMap:setTile -->
+
[[TileMap:setTile]] ''sets the index of the tile''<br/><!--GIDEROSMTD:TileMap:setTile(x,y,tx,ty,flip,color,alpha) sets the index of the tile-->
[[Special:MyLanguage/TileMap:shift|TileMap:shift]] ''<translate>shifts the tile map</translate>''<br/><!-- GIDEROSMTD:TileMap:shift -->
+
[[TileMap:shift]] ''shifts the tile map''<br/><!--GIDEROSMTD:TileMap:shift(dx,dy) shifts the tile map-->
 +
 
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Events</translate> ===
+
=== Events ===
=== <translate>Constants</translate> ===
+
=== Constants ===
[[Special:MyLanguage/TileMap.FLIP_DIAGONAL|TileMap.FLIP_DIAGONAL]]<br/><!-- GIDEROSCST:TileMap.FLIP_DIAGONAL -->
+
[[TileMap.FLIP_DIAGONAL]] '''1'''<br/><!--GIDEROSCST:TileMap.FLIP_DIAGONAL 1-->
[[Special:MyLanguage/TileMap.FLIP_HORIZONTAL|TileMap.FLIP_HORIZONTAL]]<br/><!-- GIDEROSCST:TileMap.FLIP_HORIZONTAL -->
+
[[TileMap.FLIP_HORIZONTAL]] '''4'''<br/><!--GIDEROSCST:TileMap.FLIP_HORIZONTAL 4-->
[[Special:MyLanguage/TileMap.FLIP_VERTICAL|TileMap.FLIP_VERTICAL]]<br/><!-- GIDEROSCST:TileMap.FLIP_VERTICAL -->
+
[[TileMap.FLIP_VERTICAL]] '''2'''<br/><!--GIDEROSCST:TileMap.FLIP_VERTICAL 2-->
 
|}
 
|}
 +
 +
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 15:33, 13 July 2023

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
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)

Methods

TileMap.new creates a new TileMap instance
TileMap:clearTile sets an empty tile at given indices
TileMap:getTile returns the index of the tile
TileMap:setRepeat indicates if the tilemap should repeat itself
TileMap:setTexture changes the tile texture/atlas used by the tilemap
TileMap:setTile sets the index of the tile
TileMap:shift shifts the tile map

Events

Constants

TileMap.FLIP_DIAGONAL 1
TileMap.FLIP_HORIZONTAL 4
TileMap.FLIP_VERTICAL 2