Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Accessing custom properties inside the frames object?


WombatTurkey
 Share

Recommended Posts

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:

41bf6b567c64fb5d76d17d654c2dc558.png

 

 

But, my custom properties left and top are not there. Am I looking in the right place? 

Link to comment
Share on other sites

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            ));

6befb8613f47df461e197f9de7274c4b.png

 

 

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

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.

Link to comment
Share on other sites

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

 Share

  • Recently Browsing   0 members

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