fariazz Posted March 14, 2018 Share Posted March 14, 2018 I was wondering if there is a way to add a custom property to all the sprites when creating a group, something like an "extend" property on the config object, similar to that of Scenes: this.enemies = this.add.group({ key: 'dragon', repeat: 5, setXY: { x: 120, y: 100, stepX: 70, stepY: 20 }, //proposed idea extend: { gold: 2, silver: 1 } }); Is there a way currently to set a property to all the elements of a group? from the source code I only found Phaser.Action.Call which can be used for this. Link to comment Share on other sites More sharing options...
rich Posted March 14, 2018 Share Posted March 14, 2018 Nope, but it would be a simple and small add. Feel free to submit a PR, or just open an issue as a feature request. Some thoughts though: Would it set the property if it didn't exist? If the property did exist, would it replace the current value, or skip it? (non destructive) Link to comment Share on other sites More sharing options...
fariazz Posted March 15, 2018 Author Share Posted March 15, 2018 19 hours ago, rich said: Some thoughts though: Would it set the property if it didn't exist? If the property did exist, would it replace the current value, or skip it? (non destructive) Not sure, I guess it would do whatever `extend` does for Scene objects. Will have a look at how it's implemented for scenes and see what I can do Link to comment Share on other sites More sharing options...
fariazz Posted March 16, 2018 Author Share Posted March 16, 2018 Had a look at Phaser.GameObjects.Group#createFromConfig but couldn't think of an easy way to add something like what scenes have: if (sceneConfig.hasOwnProperty('extend')) { for (var propertyKey in sceneConfig.extend) { newScene[propertyKey] = sceneConfig.extend[propertyKey]; } } But also I'm not fully convinced this should be added. I kind of thought that it would be nice to have but then easily added sprite custom properties using Call on the group object in my game: Phaser.Actions.Call(this.enemies.getChildren(), function(enemy) { enemy.speed = Math.random() * 2 + 1; }, this); Maybe it's best not to add so many things and see what common use patterns are emerging first. samme 1 Link to comment Share on other sites More sharing options...
Recommended Posts