From 00c5d02e4e88f4ca7206516a9d6a57b68452ad66 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Wed, 31 Jan 2024 15:35:18 +0000 Subject: [PATCH] Testing Layer remove fix --- src/gameobjects/DisplayList.js | 11 +++++++++-- src/gameobjects/layer/Layer.js | 23 ++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/gameobjects/DisplayList.js b/src/gameobjects/DisplayList.js index 6b248164b..3ba362bad 100644 --- a/src/gameobjects/DisplayList.js +++ b/src/gameobjects/DisplayList.js @@ -236,11 +236,18 @@ var DisplayList = new Class({ { var list = this.list; - while (list.length) + console.log('DisplayList.shutdown', list.length); + + for (var i = 0; i < list.length; i++) { - list[0].destroy(true); + list[i].destroy(true); } + // while (list.length) + // { + // list[0].destroy(true); + // } + this.events.off(SceneEvents.SHUTDOWN, this.shutdown, this); }, diff --git a/src/gameobjects/layer/Layer.js b/src/gameobjects/layer/Layer.js index 98086bb57..595a1609d 100644 --- a/src/gameobjects/layer/Layer.js +++ b/src/gameobjects/layer/Layer.js @@ -642,12 +642,12 @@ var Layer = new Class({ * * @param {Phaser.GameObjects.GameObject|Phaser.GameObjects.GameObject[]} child - The Game Object, or array of Game Objects, to be removed from the Layer. * @param {boolean} [destroyChild=false] - Optionally call `destroy` on each child successfully removed from this Layer. + * @param {boolean} [skipCallback=false] - Skip calling the List.removeCallback. * * @return {this} This Layer instance. - */ - remove: function (child, destroyChild) + remove: function (child, destroyChild, skipCallback) { - var removed = List.prototype.remove.call(this, child); + var removed = List.prototype.remove.call(this, child, skipCallback); if (destroyChild && removed) { @@ -664,6 +664,7 @@ var Layer = new Class({ return this; }, + */ /** * Removes all Game Objects from this Layer. @@ -829,11 +830,15 @@ var Layer = new Class({ */ addChildCallback: function (gameObject) { - gameObject.once(GameObjectEvents.DESTROY, this.remove, this); + var displayList = gameObject.displayList; - if (gameObject.displayList && gameObject.displayList !== this) + if (displayList && displayList !== this && displayList.exists(gameObject)) { - gameObject.removeFromDisplayList(); + displayList.remove(this, true); + + displayList.queueDepthSort(); + + gameObject.displayList = null; } if (!gameObject.displayList) @@ -861,8 +866,6 @@ var Layer = new Class({ */ removeChildCallback: function (gameObject) { - gameObject.off(GameObjectEvents.DESTROY, this.remove, this); - this.queueDepthSort(); gameObject.displayList = null; @@ -1041,6 +1044,8 @@ var Layer = new Class({ */ destroy: function (fromScene) { + console.log('Layer.destroy', this.list.length); + // This Game Object has already been destroyed if (!this.scene || this.ignoreDestroy) { @@ -1062,7 +1067,7 @@ var Layer = new Class({ if (this.displayList) { - this.displayList.remove(this, true); + this.displayList.remove(this, true, false); this.displayList.queueDepthSort(); }