Skip to content

Commit 3ec63c6

Browse files
committed
Only remove from displayList if set. Fix phaserjs#5413
1 parent f528265 commit 3ec63c6

2 files changed

Lines changed: 8 additions & 23 deletions

File tree

src/gameobjects/GameObject.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,9 @@ var GameObject = new Class({
673673
* @method Phaser.GameObjects.GameObject#destroy
674674
* @fires Phaser.GameObjects.Events#DESTROY
675675
* @since 3.0.0
676-
*
677-
* @param {boolean} [fromScene=false] - Is this Game Object being destroyed as the result of a Scene shutdown?
678676
*/
679-
destroy: function (fromScene)
677+
destroy: function ()
680678
{
681-
if (fromScene === undefined) { fromScene = false; }
682-
683679
// This Game Object has already been destroyed
684680
if (!this.scene || this.ignoreDestroy)
685681
{
@@ -691,11 +687,15 @@ var GameObject = new Class({
691687
this.preDestroy.call(this);
692688
}
693689

690+
this.removeAllListeners();
691+
this.resetPostPipeline(true);
692+
694693
this.emit(Events.DESTROY, this);
695694

696-
if (!fromScene)
695+
if (this.displayList)
697696
{
698697
this.displayList.remove(this);
698+
this.displayList.queueDepthSort();
699699
}
700700

701701
if (this.input)
@@ -719,22 +719,12 @@ var GameObject = new Class({
719719
this.body = undefined;
720720
}
721721

722-
this.resetPostPipeline(true);
723-
724-
// Tell the Scene to re-sort the children
725-
if (!fromScene)
726-
{
727-
this.displayList.queueDepthSort();
728-
}
729-
730722
this.active = false;
731723
this.visible = false;
732724

733725
this.scene = undefined;
734726
this.displayList = undefined;
735727
this.parentContainer = undefined;
736-
737-
this.removeAllListeners();
738728
}
739729

740730
});

src/gameobjects/layer/Layer.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
22
* @author Richard Davey <rich@photonstorm.com>
3-
* @author Felipe Alfonso <@bitnenfer>
43
* @copyright 2020 Photon Storm Ltd.
54
* @license {@link https://opensource.org/licenses/MIT|MIT License}
65
*/
@@ -704,13 +703,9 @@ var Layer = new Class({
704703
* @method Phaser.GameObjects.Layer#destroy
705704
* @fires Phaser.GameObjects.Events#DESTROY
706705
* @since 3.50.0
707-
*
708-
* @param {boolean} [fromScene=false] - Is this Game Object being destroyed as the result of a Scene shutdown?
709706
*/
710-
destroy: function (fromScene)
707+
destroy: function ()
711708
{
712-
if (fromScene === undefined) { fromScene = false; }
713-
714709
// This Game Object has already been destroyed
715710
if (!this.scene || this.ignoreDestroy)
716711
{
@@ -723,7 +718,7 @@ var Layer = new Class({
723718

724719
this.emit(GameObjectEvents.DESTROY, this);
725720

726-
if (!fromScene && this.displayList)
721+
if (this.displayList)
727722
{
728723
this.displayList.remove(this);
729724
this.displayList.queueDepthSort();

0 commit comments

Comments
 (0)