How is the tile data of a TileMap stored?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By FireSide_01

I looked into a scene file, and it looks like it’s stored in a PoolIntArray. But I can’t seem to figure out what these numbers mean.

:bust_in_silhouette: Reply From: njamster

There are three numbers added to the PoolIntArray for each tile you add:

  1. the id of the cell the tile occupies
  2. the id of the tile in the lists of all tiles inside your tileset
  3. the id of the sub-tile if it’s an atlas-tile, else it’s set to zero

What about the flip flags? Those must be in there too? flip_x, flip_y, and transpose?

set_cell ( int x, int y, int tile, bool flip_x=false, bool flip_y=false, bool transpose=false, Vector2 autotile_coord=Vector2( 0, 0 ) )

rakkarage | 2020-09-23 17:18

Yes. They are encoded by offsetting the id of the tile (the second value):

flip_x: add 2^29 = 536870912
flip_y: add 2^30 = 1073741824
flip_x AND flip_y: add 2^29 + 2^30 = 1610612737
rotate_left: add 2^30 = 1073741824 and invert the sign
rotate_right: add 2^29 + 2^30 = 1610612737 and invert the sign

njamster | 2020-09-25 12:58