Jump to content

Storing data in sprite object


afuriousengine
 Share

Recommended Posts

Trying to figure out how to store data in a sprite object -

 

I have a bunch of sprites moving around the map trying to shoot each other. I'd like to give each sprite an ammunition count and have the count displayed when a player mouseovers the sprite.

 

What's the best way of handling this?

 

Right now I'm storing ammo in a separate global array, but I am not sure how to link each sprite with its data. I know that the other way is to store ammo on the sprite itself, but I'm not sure how to add an ammunition property.

 

Help!

Link to comment
Share on other sites

You could extend the sprite object like in the following example : http://phaser.io/examples/v2/sprites/extending-sprite-demo-1

 

Or you could add a property directly on each object like  

var spriteA = game.add.sprite(100, 100, 'key');spriteA.property= 'value';

If you are new to javascript , check the following article which gives more details about objects : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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