I want to import an json exported map from tiled. In my game, I want to import this and load images/textureregions as an array. The idea is, that every ID included within the data-block of my map-export can resolved as an index within the array. The probleme here is, that if I have a lot of tilesets and change some of them in future (like adding or deleting images) the GID aren’t linear anymore like in the following example where it goes 0 - 1- (and than jumping to) 4 this:
“tiles”:
{
“0”:
{
“image”:"…",
“imageheight”:183,
“imagewidth”:183
},
“1”:
{
“image”:"…",
“imageheight”:183,
“imagewidth”:183,
},
“4”:
{
“image”:"…",
“imageheight”:183,
“imagewidth”:183
}
},
so is there a way to avoid this? Otherwise if I try doing my approach like explained, may array would have a lot of unused null-pointers which will be a waste of memory IMHO.
That would save some space because an array of tiles would be less sparse, but as tilesets can be referenced from multiple maps, this would only be possible for embedded tilesets.
To defrag an external tileset (and change all the GIDs in referencing maps) an external tool (could be a script) might be better suited because if you invoke it, it implies that you know what you’re doing.
Also I don’t think a bunch of null pointers would be such a waste, unless you’re making a game for some old hardware.
I’ve recently added a bunch of export options, and I guess this could be added as an additional option when the embedding of tilesets is enabled.
However, I also really doubt that the waste will be in any way significant. In Tiled, the tiles are looked up using a hash map anyway, which keeps the amount of space wasted reasonable regardless of the size of the gaps, at the cost of a slightly slower lookup.