Testing Layer remove fix

This commit is contained in:
Richard Davey 2024-01-31 15:35:18 +00:00
parent 7420a998c7
commit 00c5d02e4e
2 changed files with 23 additions and 11 deletions

View file

@ -236,11 +236,18 @@ var DisplayList = new Class({
{ {
var list = this.list; 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); this.events.off(SceneEvents.SHUTDOWN, this.shutdown, this);
}, },

View file

@ -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 {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} [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. * @return {this} This Layer instance.
*/ remove: function (child, destroyChild, skipCallback)
remove: function (child, destroyChild)
{ {
var removed = List.prototype.remove.call(this, child); var removed = List.prototype.remove.call(this, child, skipCallback);
if (destroyChild && removed) if (destroyChild && removed)
{ {
@ -664,6 +664,7 @@ var Layer = new Class({
return this; return this;
}, },
*/
/** /**
* Removes all Game Objects from this Layer. * Removes all Game Objects from this Layer.
@ -829,11 +830,15 @@ var Layer = new Class({
*/ */
addChildCallback: function (gameObject) 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) if (!gameObject.displayList)
@ -861,8 +866,6 @@ var Layer = new Class({
*/ */
removeChildCallback: function (gameObject) removeChildCallback: function (gameObject)
{ {
gameObject.off(GameObjectEvents.DESTROY, this.remove, this);
this.queueDepthSort(); this.queueDepthSort();
gameObject.displayList = null; gameObject.displayList = null;
@ -1041,6 +1044,8 @@ var Layer = new Class({
*/ */
destroy: function (fromScene) destroy: function (fromScene)
{ {
console.log('Layer.destroy', this.list.length);
// This Game Object has already been destroyed // This Game Object has already been destroyed
if (!this.scene || this.ignoreDestroy) if (!this.scene || this.ignoreDestroy)
{ {
@ -1062,7 +1067,7 @@ var Layer = new Class({
if (this.displayList) if (this.displayList)
{ {
this.displayList.remove(this, true); this.displayList.remove(this, true, false);
this.displayList.queueDepthSort(); this.displayList.queueDepthSort();
} }