j0hnskot Posted May 31, 2014 Share Posted May 31, 2014 Hello there! I've set some properties on the tiles i used when i created a map in Tiled. How can i get those properties in phaser?Is there a reference? Link to comment Share on other sites More sharing options...
j0hnskot Posted May 31, 2014 Author Share Posted May 31, 2014 I found that map.tilesets[0].tilePropertiesis that the correct reference i should use? Link to comment Share on other sites More sharing options...
botman Posted May 31, 2014 Share Posted May 31, 2014 Each individual tile will also have any properties from Tiled set on it. E.g.var tile = map.getTile( x, y, 'layer_name' );alert( tile.properties.foo );Not that it adds much, but here's the relevant doc:http://docs.phaser.io/Phaser.Tile.html#properties Link to comment Share on other sites More sharing options...
j0hnskot Posted May 31, 2014 Author Share Posted May 31, 2014 I already did that before asking this question.The result of : var tile = map.getTile( 1,1, 'Tile Layer 1' );console.log( tile.properties);is Object {} . properties are empty. To be sure i entered properties to every tile , but still. Nothing on tile.properties. But map.tilesets[0].tileProperties got every property set! Am i doing something wrong? Link to comment Share on other sites More sharing options...
botman Posted May 31, 2014 Share Posted May 31, 2014 Oh, hmm, I'm not sure sorry, I'm new to this myself. Does this help? It links to the relevant part of the source code. http://www.html5gamedevs.com/topic/4472-116-extract-tiles-properties-from-tiled/ Could your problem be the layer name? Link to comment Share on other sites More sharing options...
j0hnskot Posted May 31, 2014 Author Share Posted May 31, 2014 I tried to make a map with only 1 layer and only 1 tile. This is the code var game = new Phaser.Game(640, 800, Phaser.CANVAS, '', {preload: preload, create: create});function preload(){game.load.tilemap('map2', 'assets/maps/map2.json', null, Phaser.Tilemap.TILED_JSON);game.load.image('tiles', 'assets/grass.png');}var map;var layer;function create() { game.stage.backgroundColor = '#787878'; map = game.add.tilemap('map2'); // The first parameter is the tileset name, as specified in the Tiled map editor (and in the tilemap json file) // The second parameter maps this name to the Phaser.Cache key 'tiles' map.addTilesetImage('grass', 'tiles'); layer = map.createLayer('Tile Layer 1'); // This resizes the game world to match the layer dimensions layer.resizeWorld(); var tile = map.getTile( 0, 0, 'Tile Layer 1' );console.log( tile.properties );and this is the json :{ "height":1, "layers":[ { "data":[1], "height":1, "name":"Tile Layer 1", "opacity":1, "type":"tilelayer", "visible":true, "width":1, "x":0, "y":0 }], "orientation":"orthogonal", "properties": { }, "tileheight":32, "tilesets":[ { "firstgid":1, "image":"..\/grass.png", "imageheight":32, "imagewidth":32, "margin":0, "name":"grass", "properties": { }, "spacing":0, "tileheight":32, "tileproperties": { "0": { "1":"11" } }, "tilewidth":32 }], "tilewidth":32, "version":1, "width":1}Do anyone see a mistake here? I really can't see what i'm doing wrong. Link to comment Share on other sites More sharing options...
wayfinder Posted May 31, 2014 Share Posted May 31, 2014 Object layers (to be used with createFromObjects) are apparently different from tile layers (to be used with createLayer). In Tiled, as far as I can see, you cannot give a single tile on a layer its own properties, only to the master tile in the tileset, which is then instanced in the tile layer, and all instances have the same properties, stored in the tileset and not the layer. Objects on object layers however have per-instance properties which are automatically copied to the instances created by createFromObjects. So the way to go is apparently to use the tileset. Highly impractical if you don't know which property you are looking for, but there it is map.tilesets[setindex].tileProperties[tileindex]Edit: tileindex, by the way, seems to be per-tileset and not equal to the tile's index property... so it's tile.index - tileset.firstgid or something. *sigh* Tilde 1 Link to comment Share on other sites More sharing options...
j0hnskot Posted May 31, 2014 Author Share Posted May 31, 2014 Thats what i was using wayfinder, i just hoped there is a better solution! Thank you all for your effort! Link to comment Share on other sites More sharing options...
n7pankake Posted January 11, 2018 Share Posted January 11, 2018 I know this is old but I made 6 objects all Type Objects with the property Health and I want to destroy those objects when their health reach 0 how I do I access the property and modify the value ? Link to comment Share on other sites More sharing options...
Recommended Posts