Loupax Posted March 16, 2014 Share Posted March 16, 2014 While I was working on my game, I hacked the Phaser.Group#setAll method so that if it contains groups, the setAll method is recursivelly called for them as well If anyone wants it, it's here /*** This function allows you to quickly set the same property across all children of this Group to a new value.* The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.** @method Phaser.Group#setAll* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'* @param {*} value - The value that will be set.* @param {boolean} [checkAlive=false] - If set then only children with alive=true will be updated.* @param {boolean} [checkVisible=false] - If set then only children with visible=true will be updated.* @param {number} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.*/Phaser.Group.prototype.setAll = function (key, value, checkAlive, checkVisible, operation) { if (typeof checkAlive === 'undefined') { checkAlive = false; } if (typeof checkVisible === 'undefined') { checkVisible = false; } operation = operation || 0; for (var i = 0, len = this.children.length; i < len; i++) { if(this.children[i] instanceof Phaser.Group){ this.children[i].setAll(key, value, checkAlive, checkVisible, operation); } else if ((!checkAlive || (checkAlive && this.children[i].alive)) && (!checkVisible || (checkVisible && this.children[i].visible))) { this.setProperty(this.children[i], key.split('.'), value, operation); } }} Link to comment Share on other sites More sharing options...
Recommended Posts