Sorry if it's a noob question...
I was playing around with TileMap, and with the class Tilemapmultiple.lua (from
@atilim I think...) I cannot understand what this piece of code does :
if tilemaps[tileset] then
tilemap = tilemaps[tileset]
else |
tilemaps is a table, so I was expecting tileset to be an integer (position in the table), but it's an object... so, what does it do exactly ?
Comments
The if statement is checking that it is not nil, if not it is assigning whatever is in the table at that location to tilemap.
@chuz0 Post a link to the lua file or a "larger" piece of code
here : http://giderosmobile.com/forum/discussion/699/using-tiled/p1
is the thread where @atilim posted an example with tilemapmultiple class.
Thanks for the clarifications, although I don't fully understand it...
Once stored it in a table with a string/object index, how can I iterate through the items to find what I'm looking for ?
I may be wrong, but I think it's just using the lua address of the current tileset (as returned by gid2tileset) as an index for tilemaps table.
To iterate through a table you can use pairs and ipairs, however from the main topic I assume you need to iterate through a TileMap instance to get/set tiles/objects/enemies.
Maybe there are better ways to do that, but nobody shared them so you have only my examples to check :P
Basically I save references to anything I need to access later (you lose control over local objects outside the scope in which they're created).
This is some way to get/setTile on a certain layer
http://giderosmobile.com/forum/discussion/comment/43246#Comment_43246
This is to set properties/place enemies/objects in tiled and retrieve them in your game
http://giderosmobile.com/forum/discussion/comment/39233#Comment_39233
Hope this helps
Likes: chuz0