WombatTurkey Posted October 10, 2015 Share Posted October 10, 2015 I have to add 2 extra properties to my frames to position certain items on characters. They are basically left and top properties. (will be used for x, and y placement later){ "frames": { "w1": {"frame": {"x": 1, "y":0, "w":62 , "h":86, "left": -24, "top": -12 }} }} And, I can access the frames property like so: var temp_item = game.add.sprite(0, 0, 'ItemSprite', 'w1'); console.log(temp_item._frame);And this shows: But, my custom properties left and top are not there. Am I looking in the right place? Link to comment Share on other sites More sharing options...
WombatTurkey Posted October 10, 2015 Author Share Posted October 10, 2015 Rich is probably going to kill me for this, but I made it work by modifying the source. Added new lines at 69254: /** * @property {number} bottom - The left position offset of the frame. */ this.left = left; /** * @property {number} bottom - The top position offset of the frame. */ this.top = top;And modified line 69811: newFrame = data.addFrame(new Phaser.Frame( i, frames[key].frame.x, frames[key].frame.y, frames[key].frame.w, frames[key].frame.h, key, frames[key].frame.left, frames[key].frame.top )); Probably a easier way to do this, but figured I'd give a spin if there is another way let me know and I'll mark you as the answer Link to comment Share on other sites More sharing options...
Tom Atom Posted October 10, 2015 Share Posted October 10, 2015 Hi, there are two steps that have to be done: 1) you need to add custom properties to your export ... which you have already done,2) you have to load that new property. Here you have to change Phaser's default loading function. I wrote whole article about this here: http://sbcgamesdev.blogspot.cz/2015/04/phaser-tutorial-sprites-and-custom.html (if following my article, you will get some errors if you use Phaser 2.3.0 or higher, because Phaser is not using "uuid" more. But it is easy to fix it - just delete it). ... aah you just posted your answer ... with my solution you do not have to change default Phaser codebase. WombatTurkey 1 Link to comment Share on other sites More sharing options...
WombatTurkey Posted October 10, 2015 Author Share Posted October 10, 2015 Hi, there are two steps that have to be done: 1) you need to add custom properties to your export ... which you have already done,2) you have to load that new property. Here you have to change Phaser's default loading function. I wrote whole article about this here: http://sbcgamesdev.blogspot.cz/2015/04/phaser-tutorial-sprites-and-custom.html (if following my article, you will get some errors if you use Phaser 2.3.0 or higher, because Phaser is not using "uuid" more. But it is easy to fix it - just delete it). ... aah you just posted your answer ... with my solution you do not have to change default Phaser codebase. Aw, that's awesome and probably the correct way to do it. That's funny because I was just visiting that website moments ago, thank you man! Link to comment Share on other sites More sharing options...
Recommended Posts