Jump to content

[1.1.6] Extract tiles properties from Tiled?


Recommended Posts



I'm building a platformer with Phaser 1.1.6.

In tiled I have coins with a custom property called "amount" to know how much each one is worth (sometimes it's 1, or 5, or 10, or 100, etc.).


To transform the coins into sprites I do:

coins = game.add.group();map.createFromObjects('objects layer', 8, 'coin', 0, true, false, coins);

And it works fine. But how can I extract the custom properties of each coin that I set in Tiled? I'd like to do something like this:

for each coins:   coin.amount = value extracted from Tiled custom properties



Link to comment
Share on other sites

  • 5 months later...

But what is the syntax for obtaining the Tiled object's properties values?


This works fine - to set the property:

mysprite.mycustomproperty = 5;   

And the line below works perfectly well to get the property - but only if first initialised in code (as above).

var v = mysprite.mycustomproperty;

But I want mysprite.customproperty to be automatically initialised as per the Tiled property/value pair when I load json map file into my game.  So if in Tiled I right-click on the mysprite object and do Properties, I have a mycustomproperty with value of 9 then I want mysprite.mycustomproperty to be already set to 9 for me when I run my game. (Without having to populate it with any code).


I suspect there is a specific syntax I should be using eg:

var defaultvalue = mysprite.getTiledObjectPropertyValue('mycustomproperty')

But I don't know what is the correct syntax to use.  (The above is wrong, just an example of what I'm trying to find).




Link to comment
Share on other sites

  • 1 year later...

+1 I would like to know this as well. I'm surprised the map object in Phaser doesn't have all the key/values from the Tiled map.


ps. if you add the custom data on the main properties key, that stuff is available in the map object.



map = this.game.add.tilemap('map');console.log(map.properties)
Link to comment
Share on other sites

  • 2 years later...

you are confusing Gid with properties.





I guess what he wants to do is to import the custom property lets say 50 and when he collect THAT coin he gets 50 POINTS (cash/w/e) 
if anyone find out how to get that custom property let me know cause I want to destroy my rocks every 3 hits and I can't find a way to use the Hitpoints value I set up... 

Edit: I found out how to do it for this example it would be rocks:



and I want the custom property Hitpoints so all you have to do is:

rocks.Hitpoints (And it should work)




here I have that when an arrow hit one of the rocks from the group destroy the rock :3 hope this help

Link to comment
Share on other sites


  • Recently Browsing   0 members

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