Reputation: 17
I am currently finding way to import a tile map made in Tiled into phaser.
In Tiled,i created a tileset named "terrain", set the custom properties for each tile type in the tileset, fill the map with some tiletype and then export the map as json.
Then in phaser, i load said json into phaser as tilemap.
//load the json into a tilemap
this.game.load.tilemap('plain', 'Content/map/plain.json', null, Phaser.Tilemap.TILED_JSON);
//initialize a new map from a loaded tile map
this.map = this.game.add.tilemap('plain');
//set the map tileset image
this.map.addTilesetImage('terrain', 'terrain');
//create the layer with the same name in the tilemap
this.layer = this.map.createLayer('background');
After that, i try to access tileProperties of tileset "terrain" of the loaded tilemap.
//get the tileindex of a tile at the coordinate (0,0)
var tileindex = this.map.getTile(0, 0, 'background').index;
//get the tileset index of the tileset that is named "terrain"
var tilesetindex = this.map.getTilesetIndex('terrain');
// get the tileset
var tileset = this.map.tilesets[tilesetindex];
But then, i found out that there is no tileProperties in class TileSet.
So i go into the github repository and search for "tileProperties" and i found that there is a piece of code in TileMapParser.js that set the tileProperties for a tileset but there is no tileProperties in class TileSet's definition.
My question is why is there a code that set the tileProperties of class TileSet but there is no such property in class TileSet's definition?
Upvotes: 1
Views: 180
Reputation: 51
If you're trying to access the tile properties that you set in Tiled, you can do it like this:
// get a reference to the tile
var tile = this.map.getTile(0, 0, 'background');
// access the property
var property = tile.properties.property;
Where property is the name of the property you're trying to access, which in your case would be terrain. If you're not sure, you can poke around in the json exported from Tiled.
This example on the phaser website is a really good demonstration of this.
Hopefully this helps!
Upvotes: 1