1
\$\begingroup\$

I have about 16 tiles in my spritesheet that I'm using for Tiled, and I'm trying to build a GID map so I can properly convert them in my game. I'm using the JSON format for my map, if that helps.

What I would like is a way to say "this sprite is most definitely this GID" but there doesn't appear to be any option in the Tiled GUI to get a GID for a sprite.

I need this so I can figure out which tiles correspond with which GID when I load the map.

What can I do to accomplish this? Or is there a better way to do what I want?

\$\endgroup\$
7
  • 1
    \$\begingroup\$ The GID is used for indexing into all tilesets when the file is written to another format. There hasn't been much reason to expose the GID to the GUI for anything I have done with Tiled. I want more clarification on exactly what you need the GID for in the GUI. \$\endgroup\$ Commented Jun 25, 2014 at 3:34
  • \$\begingroup\$ i am told that the gid should just be the offset of the tile in the sprite sheet + the tilesheet index. \$\endgroup\$
    – jorb
    Commented Jun 25, 2014 at 3:39
  • \$\begingroup\$ @jorb You are right but it's a process that requires searching through the map to find the given tileset index. This at "FindTileset" is an example of finding the tileset to use given the GID. \$\endgroup\$ Commented Jun 25, 2014 at 3:44
  • \$\begingroup\$ @connor I need to know what tile to load when I look at the data. I don't know how to accomplish that without knowing the gid. Also, I counted and it didn't seem correct for my spritesheet but I'll check again. \$\endgroup\$
    – Seiyria
    Commented Jun 25, 2014 at 11:25
  • \$\begingroup\$ Additionally, I'm not limited to the Tiled map editor. If there's a better one that outputs to JSON I'm willing to take a look at it. \$\endgroup\$
    – Seiyria
    Commented Jun 25, 2014 at 12:22

1 Answer 1

0
\$\begingroup\$

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 firstgids 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.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for this answer -- it's pretty good. Unfortunately, I got pretty far in and I don't want to redo 50+ maps, so I think for now things will just keep getting added to the same tileset for now :/ -- Currently my maps are split by layer, though, so there's the "blocking layer" and the "terrain layer" -- so that's not too bad to work with. \$\endgroup\$
    – Seiyria
    Commented Dec 22, 2014 at 5:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .