Jump to content

How to interprete tileproperties in JSON tile maps


jaga
 Share

Recommended Posts

Hi

I'm playing a bit with this example. 

http://phaser.io/examples/v2/tilemaps/tile-properties

In this example there is a function which is responsible for displaying properties for the given tile:

function getTileProperties() {

    var x = layer.getTileX(game.input.activePointer.worldX);
    var y = layer.getTileY(game.input.activePointer.worldY);

    var tile = map.getTile(x, y, layer);
    
    // Note: JSON.stringify will convert the object tile properties to a string
    currentDataString = JSON.stringify( tile.properties );

    tile.properties.wibble = true;

}

 

Here is a file used as a map
https://github.com/photonstorm/phaser-examples/blob/master/examples/assets/tilemaps/maps/tile_properties.json

Part of the file which contains the properties information goes like

"tileproperties":
            {
             "135":
                {
                 "bonus":"100"
                },
             "29":
                {
                 "start":"true"
                },
             "72":
                {
                 "speed":"200"
                },
             "99":
                {
                 "goal":"true"
                }

 

Question is: how to interprete those values "135", "29" (...) values, because they don't corresponds to the ids listed in the beginning of the map file ("data":[34, 34, 34, (...)).

Below is a screenshot of game - I've selected the tile and the corresponding property - why "99"

property_of_tile.thumb.jpg.0f56c648c87be4b7fc12ca24e8811d54.jpg

 

Link to comment
Share on other sites

the map is 20 across 
and begins with index one 

click on the 2nd square of row two and you'll see the property "start" 

since the rows are 20 across the "start" tile is tile number 22 

find the 22nd element in the data array of the json file 

it has a value of 30 

so tile ID 30 should be the "start" tile 

but according to the tileproperties in the json file tile ID 29 is the tile with a property of start 

so it looks like the tileproperties starts counting at zero (0 - 29), but the data counts counting at one (1 - 30)

you can change currentDataString to this 

    currentDataString = "Tile at position " + ( (y * map.width) + (x+1) ) + " has an ID of " + tile.index + " -- x = " + x + " y = " + y + " -- "  + JSON.stringify( tile.properties ); 


to see more info 

 

Link to comment
Share on other sites

I think everyone eventually gets confused by this.

The indexes in tileset.tileproperties refer to the tileset itself. The indexes in layers[*].data are mapped from those indexes by adding tileset.firstgid ("first global ID"; always 1 for the first or unique tileset).

So the first tile [0] in the tileset is assigned global ID 1 when it appears in a layer, and so on.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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