Merge pull request #6686 from samme/fix/container-destroy-child

Fix removing destroyed Container children
This commit is contained in:
Richard Davey 2024-01-12 17:57:57 +00:00 committed by GitHub
commit e91551b4c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -438,7 +438,7 @@ var Container = new Class({
*/
addHandler: function (gameObject)
{
gameObject.once(Events.DESTROY, this.remove, this);
gameObject.once(Events.DESTROY, this.onChildDestroyed, this);
if (this.exclusive)
{
@ -976,7 +976,7 @@ var Container = new Class({
{
if (list[i] && list[i].scene)
{
list[i].off(Events.DESTROY, this.remove, this);
list[i].off(Events.DESTROY, this.onChildDestroyed, this);
list[i].destroy();
}
@ -1452,6 +1452,25 @@ var Container = new Class({
this.tempTransformMatrix.destroy();
this.list = [];
},
/**
* Internal handler, called when a child is destroyed.
*
* @method Phaser.GameObjects.Container#onChildDestroyed
* @protected
* @since 3.70.1
*/
onChildDestroyed: function (gameObject)
{
ArrayUtils.Remove(this.list, gameObject);
if (this.exclusive)
{
gameObject.parentContainer = null;
gameObject.removedFromScene();
}
}
});