Your easiest option is to just use an existing library or game engine that supports the Tiled map format. Then you don't have to worry about GIDs or which sprites to use; you simply load the Tiled map and the associated spritesheets, and the Tiled API will let you render the map on a per-layer basis - no need to worry about individual tiles or sprites.
This is because the GID is an internal ID used by the Tiled map format; it's an ID that uniquely identifies a type of tile in a map, given that the map could contain multiple layers and spritesheets. The map itself is expressed as a bunch of layers, and each layer contains a big list of GIDs. Elsewhere in the map file, there will be a section describing the tilesets used, and each of them will occupy a range of GIDs. That is, GIDs 1-128 (for example) might use the first tileset, GIDs 129-512 might use the second and so on. You can see how GIDs can be fragile: if you change the order of the tilesets, the ranges of the GIDs will change.
How to tell which tiles are which
This is all fine if all you care about is rendering. For games this is not nearly enough. We might want to know whether tiles are:
- Impassable, or opaque or whatever, so the engine can treat them as such
- Where we need to spawn enemies, or place pickups etc.
This is the real problem we want to solve; GID is just a means to this and is quite poor in that regard too. We have very little control over it; we can't tell Tiled that "instead of GID 123, I want to use wall or w as the value so I can look for this in code", or "always use GID 1 as tile #1 in the Walls tileset". So I suggest keeping away from exact values of GID and using one of the following techniques:
Differentiate special tiles by tileset
That is, instead of remembering that GIDs 56-68 are walls (and breaking once you update the tilesets/layers), you keep all your walls in the one tileset/spritesheet, give the tileset a name (e.g. Walls), and treating all tiles that came from that tilesets as walls. You still need to compare the GID with all the firstgid
s of all the tilesets to figure out which tileset that GID belongs to, but you can now add/remove wall tiles with impunity.
Differentiate special tiles by layer
You can also keep all walls in the same layer, and give it a special name to look for. The downside is that your map editors will need to take care and draw only walls in the wall layer and everything else on other layers, lest you end up with intangible wall-tiles and impassable non-wall-tiles because they were on the wrong layer. The upside is that you have full freedom in composing your tilesets, to suit your artist / texture packer.
Unfortunately both approaches requires some human diligence, whether that's the people that make the tilesets or the people making the maps. For a more fool-proof solution, you may need to make your own modified version of Tiled Map Editor that enforces said restrictions.