Groups will now listen for a destroy event from any Game Object added to them, and if received will automatically remove that GameObject from the Group. Fix #3418

This commit is contained in:
Richard Davey 2018-03-20 01:08:45 +00:00
parent cb5b12e9d3
commit b6f2c80ae6
2 changed files with 12 additions and 5 deletions

View file

@ -29,6 +29,7 @@ A special mention must go to @orblazer for their outstanding assistance in helpi
* Camera.flash now has an optional `callback` argument that is invoked when the effect completes (thanks @pixelscripter)
* Camera.fadeIn is a new method that will fade the camera in from a given color (black by default) and then optionally invoke a callback. This is the same as using Camera.flash but with an easier to grok method name. Fix #3412 (thanks @Jerenaux)
* Camera.fadeOut is a new method that will fade the camera out to a given color (black by default) and then optionally invoke a callback. This is the same as using Camera.fade but with an easier to grok method name. Fix #3412 (thanks @Jerenaux)
* Groups will now listen for a `destroy` event from any Game Object added to them, and if received will automatically remove that GameObject from the Group. Fix #3418 (thanks @hadikcz)
### Bug Fixes

View file

@ -406,6 +406,8 @@ var Group = new Class({
}
}
child.on('destroy', this.remove, this);
return this;
},
@ -462,6 +464,8 @@ var Group = new Class({
}
}
child.off('destroy', this.remove, this);
return this;
},
@ -479,14 +483,16 @@ var Group = new Class({
{
if (removeFromScene === undefined) { removeFromScene = false; }
if (removeFromScene)
var children = this.children;
for (var i = 0; i < children.size; i++)
{
var children = this.children;
var gameObject = children.entries[i];
for (var i = 0; i < children.size; i++)
gameObject.off('destroy', this.remove, this);
if (removeFromScene)
{
var gameObject = children.entries[i];
this.scene.sys.displayList.remove(gameObject);
if (gameObject.preUpdate)