Tileset parsing question: transformations and objectalignment


I am currently writing a parser for JSON Tiled maps and stumbled over those two properties of tilesets (transformations and objectalignment).
I am not sure how these two are expected to work exactly.

When editing in Tiled, it seems that I can freely flip and rotate tiles however I like without enabling any transformations in the tileset. What then is the purpose of the transformations data? The documentation (link) says, this describes transformations that are allowed in a tileset. But Tiled itself seems to ignore this entirely and exports gids with transformation info just fine. What exactly is the expected behaviour of a parser here? Since I’m trying to display a map the same way it is shown in Tiled, I’m inclined to ignore this section as well.

The same question, what is the expected behaviour, goes for objectalignment. The documentation (link) states that this controls the alignment for “tile objects”. What exactly are “tile objects”? The documentation mentions these only sparsely, giving me not enough clues to understand this. My first thought was that this alignment might be applied whenever a tileset is used which tiles are either bigger or smaller than the map grid size. At least with smaller tiles, Tiled puts these in the bottomleft corner, making it consistent with the default value. However, changing objectalignment in Tiled did not change the display of smaller tiles for me. The only other thing I could relate to “tile objects” were tiles placed in object layers. But it seems that these can be positioned freely throughout the map, making it seem that any kind of alignment is unnecessary here. So, what should objectalignment do?

Thank you in advance!

Allowed Transformations are used by the Terrain tools (and optionally by scripted tools), they determine whether these tools are allowed to flip/rotate tiles. This can be used to expand the capabilities of a tileset that is missing various terrain shapes, or to add cosmetic variation by allowing tiles to serve multiple roles. In a parser, you should just save this property so it’s accessible to the user, but you don’t need to do anything based on its value.

Object Alignment is for, as you said, Tile Objects, the Objects that you get when you use “Insert Tile” on an Object Layer. This determines where the Tile Object is relative to the object’s position, which is essentially its origin/pivot point. By default, for consistency with tile layers, this is bottom left, but many people like to set it to top left so that Tile Objects behave more like Rectangle Objects. You can see the effect of this property by placing a Tile Object at 0,0 and seeing where it’s drawn as you change the value of that property in the Tileset.
It’s up to you whether you want to just save this property and let the user position their in-engine objects appropriately, or if you want to use that property to convert all objects to the same origin point. I’d probably do the former, because it’s simpler, and because some users may have specific reasons to want a particular origin point and wouldn’t want to lose that data after parsing.

1 Like

Much obliged!

If you want to be super helpful to developers using your library, provide both the raw coordinates unaffected by Object Alignment, and normalised coordinates, so that people who don’t care and were only using object alignment as an aid to placement within Tiled can use them conveniently. The normalised coordinates would be the top left corner of the object once the object alignment is taken into account. This would be the object’s raw position with its width and height (or half thereof) subtracted as appropriate for each alignment option.

1 Like