Jump to content

Unexpected tiles properties syntax in the latest Tiled


kurhlaa
 Share

Recommended Posts

Hi,

It seems that the latest Tiled program uses a different tiles "properties" syntax. Different from Phaser 3 expects.

Currently if I export a JSON tilemap from Tiled (version 2018.06.01) I get the following tiles descriptions:

"tilesets":[
        {
         "columns":8,
         "firstgid":1,
         "image":"warTileset_64x64.png",
         "imageheight":512,
         "imagewidth":512,
         "margin":0,
         "name":"warTileset_64x64",
         "spacing":0,
         "tilecount":64,
         "tileheight":64,
         "tiles":[
                {
                 "id":2,
                 "properties":[
                        {
                         "name":"health",
                         "type":"int",
                         "value":1
                        }]
                },
                {
                 "id":5,
                 "properties":[
                        {
                         "name":"health",
                         "type":"int",
                         "value":2
                        }]
                }],
         "tilewidth":64
        }],

If I import this into Phaser 3 - I can't access any custom property.

But if I modify JSON like this:

"tilesets":[
        {
         "columns":8,
         "firstgid":1,
         "image":"warTileset_64x64.png",
         "imageheight":512,
         "imagewidth":512,
         "margin":0,
         "name":"warTileset_64x64",
         "spacing":0,
         "tilecount":64,
         "tileheight":64,
         "tileproperties":
                {
                 "2":
                    {
                     "health": 2
                    },
                 "5":
                    {
                     "health": 3
                    }
                },
         "tilewidth":64
        }],

Then everything works as expected.

I haven't used very old versions of both Phaser and Tiled, but it seems somebody has changed his syntax, which is not supported by both projects. Or I miss something? Question of course is how to access custom properties with the latest versions of Phaser 3 and Tiled?

 

I create a tilemap in a standard way:

...
scene.load.tilemapTiledJSON('map', '1.json');
...
this.map = scene.make.tilemap({ key: 'map' });

var groundTiles = scene.map.addTilesetImage('warTileset_64x64');
var groundLayer = scene.map.createDynamicLayer('ground', groundTiles, 0, 0);
...
...
...
// Later when we process collision with specific tile
var prop = tile.properties  // No data here
...

 

Link to comment
Share on other sites

  • 1 month later...

I ran across the same issue last night when trying to read collision-shapes from Tiled in phaser. 

I wrote a quick fix to phaser 3. Replacing method getTileData with the code below enables Phaser 3 to read the new syntax of Tiled-generated json-files.

I'll  post it to github so that it'll get fixed in the official phaser release.

 

getTileData: function (tileIndex)
{
    if (!this.containsTileIndex(tileIndex)) { return null; }

    if(!this.tileIndexMap){
        this.tileIndexMap = {};
        for(var i = 0; i < this.tileData.length; i++){
            this.tileIndexMap[this.tileData[i]['id']] = this.tileData[i];
        }
    }

    return this.tileIndexMap[tileIndex - this.firstgid]; 

    // Old:
    //return this.tileData[tileIndex - this.firstgid];
},
Link to comment
Share on other sites

The stable release of Tiled (1.1.6) does not use this new format, it's only the Beta version that does. There was one version of Tiled that swapped to using an array but they quickly reverted the change because it broke too much stuff. We should support the beta version of Tiled too I guess, but not at the cost of stable versions.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...