FakeWizard Posted March 7, 2017 Share Posted March 7, 2017 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 More sharing options...
FakeWizard Posted March 7, 2017 Author Share Posted March 7, 2017 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 More sharing options...
samme Posted March 7, 2017 Share Posted March 7, 2017 You need to use force=true to create a new property with setAll: bunnies.setAll('data.test', 5, null, null, null, true) Link to comment Share on other sites More sharing options...
Recommended Posts