Climbus Posted September 5, 2014 Share Posted September 5, 2014 Hi all I'm using Phaser with json maps created by Tiled. In Phaser docs i found info that i can use parameters: http://docs.phaser.io/Phaser.Tilemap.html#createFromObjects. I tested it and it is not working corectly with maps generated in Tiled. I attached exeample. Tiled puts all parameters values in quotes: "body.velocity.x":"10". In that case object goes fast to maxVelocity.When i remove quotes manualy, object is moving with given velocity. In my example you can comment line 7 and uncomment line 8 in main.js file to check two cases. Is this Phaser bug or i'm doing something worong? ClimbusTestCreateFromObject.zip Link to comment Share on other sites More sharing options...
wayfinder Posted September 5, 2014 Share Posted September 5, 2014 I think Tiled's output is interpreted as a string, so you might have luck with trying parseInt()? Link to comment Share on other sites More sharing options...
Climbus Posted September 5, 2014 Author Share Posted September 5, 2014 I think Tiled's output is interpreted as a string, so you might have luck with trying parseInt()? I'm using Phaser internal function so i cant add parseInt in code responsible for setting parameters. I think that code dont't evaluate this string so i cant put "parseInt(10)" to Tiled. Link to comment Share on other sites More sharing options...
rich Posted September 5, 2014 Share Posted September 5, 2014 Hmm good point. I'm not sure there is an easy fix for this. If I parseInt every value then it will break string / object based properties. If I leave it as is, some properties will convert from strings to integers fine, and others won't. I'm not sure there is an easy solution for this. Link to comment Share on other sites More sharing options...
Climbus Posted September 5, 2014 Author Share Posted September 5, 2014 Hmm good point. I'm not sure there is an easy fix for this. If I parseInt every value then it will break string / object based properties. If I leave it as is, some properties will convert from strings to integers fine, and others won't. I'm not sure there is an easy solution for this. Maybe Point object can have setter for x and y values. I dont know is it posible in JS. Link to comment Share on other sites More sharing options...
Climbus Posted September 5, 2014 Author Share Posted September 5, 2014 Maybe Point object can have setter for x and y values. I dont know is it posible in JS. Something like this:a = { set x(val) { this._x = parseInt(val); }, get x() { return this._x; }}a.x = "aaa"a.x//NaNa.x = "123"a.x//123 Link to comment Share on other sites More sharing options...
rich Posted September 5, 2014 Share Posted September 5, 2014 It would need to be parseFloat, but even so the thought of doing a parseFloat on every single Point object, every single time the x or y values change, is quite terrifying to be honest. Link to comment Share on other sites More sharing options...
Recommended Posts