Jump to content

Does Group.add also remove from other groups?


mariogarranz
 Share

Recommended Posts

Well I had this code in a 1.1.6 game. It was meant to empty a whole group and move all of its children into another group:

 

while(this.group1.length > 0){  var a = this.group1.getAt(0);  group2.add(a);  this.group1.remove(a);  ...}

With version 1.2 the line "this.group1.remove(a)" is returning the following error:

 

    1. Uncaught Error: [object Object] The supplied DisplayObject must be a child of the caller [object Object] phaser20140410.js:1351
      1. PIXI.DisplayObjectContainer.removeChildphaser20140410.js:1351
      2. Phaser.Group.removephaser20140410.js:16458

 

Since "a" is grabbed from group1, there's no explanation for "a" not being in group1 other than adding it to group2 also removed it from the first group. 

Looked inside the changelog and docs but couldn't find anything about this, which apparently should work the same way it did in 1.1.x.

Link to comment
Share on other sites

The child is no longer in group1. As soon as you add it to group2 it's automatically removed from group1 and will re-parent itself to group2. This is correct new behaviour as a child can never exist in more than 1 Group at once other than as an ancestor. All you need change in your code is to get rid of the 'remove' line as it's no longer needed.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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