how can I get the next bottom element (id, class) of a selected tile without to loop through the whole tilemap? E.g.: my tile $('.gQ_tileType_4') is a rock in the game and this should be fall down if the next bottom tile $('.gQ_tileType_8') a space is. Now I loop throug the whole tilemap and compare the elements against there xy coordinates. But I think is a wrong way, because the game performance is slowing down.
1 Answers
gameQuery gives an unique id to each tiles constructed in the following way:
$.gameQuery.tileIdPrefix+name+"_"+row+"_"+column
This means that if your tilemap is called "foo" then you can access the tile at position (a,b) by writing:
$("#"+$.gameQuery.tileIdPrefi+"foo_"+a+"_"+b);
In the same way you can deduce the position (index-wise) of the tile by parsing it's id. This means that for a given tile you can find it's position and probe specifically the state of the tile just bellow.
How ever I'm not sure using tile-maps is the best solution for this since they are not supposed to change. At the moment it shouldn't cause any problems but I cannot guaranty that in a future version this wont break some functions like collision detection.
In this situation I would simply use sprites to display the elements. To make the game logic implementation of your game faster I would simply store the tiles states in a two-dimensional array as well as a reference to the associated sprite.
This way you can simply work with the array and update the associated sprites if you need to.

- 320
- 1
- 6