Jump to content

Sprite.data property


FakeWizard
 Share

Recommended Posts

Just wondering , why Phaser won't let me store any data into the Sprie.data property using the Phaser.Group.setAll() method.

this.bunnies = this.game.add.group();
this.bunnies.createMultiple(5, 'bunny');
this.bunnies.setAll('data.test', 5); 

this.bunnies.forEachExists(function(child){
  console.log(child.data)
}, this);

The documentation clearly says that this property is supposed to be used for such purposes.

Quote

data : Object
An empty Object that belongs to this Game Object.
This value isn't ever used internally by Phaser, but may be used by your own code, or
by Phaser Plugins, to store data that needs to be associated with the Game Object,
without polluting the Game Object directly.

Any ideas? I don't want to extend the Sprite object.

Link to comment
Share on other sites

ok I seem to have figured it out

this.bunnies = this.game.add.group();
this.bunnies.createMultiple(5, 'bunny');
this.bunnies.setAll('data', {test:5}); 

this.bunnies.forEachExists(function(child){
  console.log(child.data)
}, this);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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