Jump to content

Phaser.Group#setAll that checks if the children of the group are groups themselves


Recommended Posts

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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