Option to export tile data with 0-based indexes?


(Eric Richards) #1

Is there some option to export tile layer data using a base of 0, instead of 1?
I.e. In the exported data for a map, currently the first tile is referenced by an ID of 1:
“layers”:[
{
“data”:[1, 1, 1, 5, 7, 1, 1, 1, 1, 1, 1, 5, 7, 1, 2, 3, 1, 1, 1, 5, 7, 1, 5, 6, 1, 1, 1, 5, 7, 1, 5, 6, 1, 1, 2, 11, 7, 1, 5, 6, 1, 1, 5, 6, 7, 1, 8, 9, 1, 1, 5, 6, 7, 1, 1, 1],
}

Working from most non-Lua languages, the first entry in an array/collection is 0, not 1, so I’ve got to fixup all these IDs when indexing into my texture atlases and other things.


(Thorbjørn Lindeijer) #2

Actually this index also starts at 0, but 0 means “no tile” / “empty cell”. So if you’re going to subtract 1, you need to check for 0 before otherwise you’re going to use an invalid index.

There is no option for disabling support for empty cells.


(Eric Richards) #3

Thanks for the explanation.
I still think it is a little confusing, especially since if I select a tile in Tiled, under the properties window for that tile, the ID field is 0-based, and doesn’t match up with the exported data.
tile-properties


(Thorbjørn Lindeijer) #4

Right, but that ID is local to the tileset. It’s an index into the array of tiles in the tileset image, where there is no “empty cell” and 0 is simply the first tile.

The tile IDs saved in the TMX and JSON formats not only start at 1 because 0 is the empty cell, but they might also be shifted by larger amounts in case there are multiple tilesets used by the map. These are global IDs. But global IDs are not shown anywhere in Tiled because they are specific to the way the map is stored.