afuriousengine Posted March 17, 2015 Share Posted March 17, 2015 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 More sharing options...
j0hnskot Posted March 17, 2015 Share Posted March 17, 2015 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 More sharing options...
afuriousengine Posted March 17, 2015 Author Share Posted March 17, 2015 Sheesh. Thanks very much! Link to comment Share on other sites More sharing options...
Recommended Posts