toto88x Posted March 5, 2014 Share Posted March 5, 2014 Hi, 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 propertiesThanks! Link to comment Share on other sites More sharing options...
jerev Posted March 5, 2014 Share Posted March 5, 2014 The properties in the data object, loaded from tiled, are copied onto the sprite. You can see this here: http://docs.phaser.io/Tilemap.js.html#sunlight-1-line-208 Link to comment Share on other sites More sharing options...
owen Posted August 28, 2014 Share Posted August 28, 2014 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). Thanks,Owen Link to comment Share on other sites More sharing options...
eddieone Posted December 21, 2015 Share Posted December 21, 2015 +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. Example:map = this.game.add.tilemap('map');console.log(map.properties) Link to comment Share on other sites More sharing options...
drhayes Posted December 21, 2015 Share Posted December 21, 2015 For sprites, if you use the function "createFromObjects" it already does this for you. Every thing that is in your object's properties object will be assigned as a property on the sprite. You can even use this to do things like set "body.velocity.x", as per the docs. Link to comment Share on other sites More sharing options...
n7pankake Posted January 11, 2018 Share Posted January 11, 2018 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 More sharing options...
Recommended Posts