This reminds me of one my initial development stages where I was figuring out if I could depend on Tile IDs to reference a tilesheet externally. I don’t know if that’s the case here, but I’ll explain my experience just in case it proves useful.
Tiled’s Tile ID is ‘volatile’, in such a way that during the development of a map, through adding and deleting sprites, the tiles’ IDs will change and it breaks the original sequence. That means I couldn’t assume that referencing tile ID # 9 (ie tile_id - firstgid) refers to the 9th image in the tileset. In fact, there could be no ID # 9. There have been situations where I’ve gotten broken sequences, like 1, 3, 7, 10, etc.
So what I’ve learned is that there is no implicit mapping between Tile IDs and the integer sequence in which images appear in a tilesheet. You’d need to lookup a given Tile ID back in the TMX/JSON, and query the
My game engine is C2, and I’m fortunate the 3rd-party TMX loader I’m using already allows me to populate a TMX Class object with the source image so that for any given tile, I know the source image path, and use that to instantiate my sprite.