Parsing tsx files

Hi there!
I’m working with unity, trying to import an existing tileset in my random generated map.
I have parsed and reverse engineered tsx file for getting correct sprites depending on terrain type, but at the moment I’m stuck on interpreting comma separated values in the “terrain” xml attribute…like this:

<tile id=“144” terrain="5,5, , "/>

Pretty sure that’s needed for tiles transitions: i.e. tile “144” should be used when terrain “5” is found in 2 of 4 corners around the actual tile.
The point is that i can’t fully understand the logic.
Sometimes it seems that those 4 digits start from upper right counter clock wise, but every now and then the logic is completely the opposite… :frowning:

Anyone else solved this tricky logic ? :slight_smile:


Fortunately these is no need to “reverse engineer” the TSX file, because its format is documented quite extensively in the manual. Quoting from the documentation regarding the terrain attribute on tile elements:

  • terrain: Defines the terrain type of each corner of the tile, given as comma-separated indexes in the terrain types array in the order top-left, top-right, bottom-left, bottom-right. Leaving out a value means that corner has no terrain. (optional)