"Data" field in the tmx format (json)

Hello, I’m really new here, not just at the forum but as a user of this program, so, I wanted to know what is the information stored inside the ‘data’ field in the exported file.

I’m trying to develop a game just for fun, and I exported my tilemap I created in json format, so I can load it inside my game in a easy way.

But, then I thought something like, what is the value of inside this array?

In this link:

I found out that the field is an array of Gids (Global IDs), but, the reason I’m asking this is because my exported .json file, has some crazy IDs inside this array, something like: (copy-pasted) 3221225493, 1610612751 and 21.

This is the question:
These numbers represents different tiles inside a same image. But, how can I read this? Is there some format regarding it or it’s something internal to the tiled application? How can I know which ID references which tile in the json file?

Ah, the information is not corrupted as I tried to open the file using tiled, and it worked as expected.

  1. This is the image i’m using right now, which has those crazy IDs
  2. This is the entire map

And this is a printscreen of the data matrix inside the “data” field in a background layer, that has only the gray bricks and the red carpet in the image:

  • I editted it in sublime text 3 adding a ‘\n’ character to separate the lines of that big array to a more friendly matrix view, which represents the entire image.


I uploaded as a image bc when i try to upload the .json or .tmx file it says that I can’t because I’m new to this forum.


These strange values are probably cause by the tile flipping flags that flip the most significant bits of the integer, hence producing a negative value in the json.

see: http://docs.mapeditor.org/en/stable/reference/tmx-map-format/#tile-flipping

The solution is to zero these bits to get the GID:

global_tile_id = global_tile_id & 0x1FFFFFFF;

Before doing that, you should extract the horizontal, vertical and diagonal flip values to draw that tile correctly:

var flipped_horizontally = (global_tile_id & 0x80000000);
var flipped_vertically = (global_tile_id & 0x40000000);
var flipped_diagonally = (global_tile_id & 0x20000000);
1 Like

I see… I will look at it… the problem is that I am coding my game with Lua, which doesn’t have binary operators by default (Corona SDK), like standard C. But I will look at it and try to resolve myself, thanks for the reply!

If you can’t use the tile flipping bits, then you should create flipped copies of each tiles you need flipped in your tileset.

Oh yes, that works as well. I was already searching for a Lua library to do all this work but this is easier :smiley:

But if you (that is reading this right now) are like me, that has lots and lots of spritesheets and don’t want to consume 4x memory, you might take a look at this link:

But, thanks, that also solves my problem.