Skip to content

Commit 5552079

Browse files
authored
Merge pull request #5717 from rexrainbow/destroy-from-scene
Add 'fromScene' parameter in GameObject.destroy() method, and DESTROY event
2 parents c8cc337 + 07ff5de commit 5552079

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/gameobjects/GameObject.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,21 +821,25 @@ var GameObject = new Class({
821821
* @method Phaser.GameObjects.GameObject#destroy
822822
* @fires Phaser.GameObjects.Events#DESTROY
823823
* @since 3.0.0
824+
*
825+
* @param {boolean} fromScene - True if this Game Object is destroyed from scene, false if not.
824826
*/
825-
destroy: function ()
827+
destroy: function (fromScene)
826828
{
827829
// This Game Object has already been destroyed
828830
if (!this.scene || this.ignoreDestroy)
829831
{
830832
return;
831833
}
832834

835+
if (fromScene === undefined) { fromScene = false; }
836+
833837
if (this.preDestroy)
834838
{
835839
this.preDestroy.call(this);
836840
}
837841

838-
this.emit(Events.DESTROY, this);
842+
this.emit(Events.DESTROY, this, fromScene);
839843

840844
this.removeAllListeners();
841845

src/gameobjects/events/DESTROY_EVENT.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
* @since 3.0.0
1616
*
1717
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object which is being destroyed.
18+
* @param {boolean} fromScene - True if this Game Object is destroyed from scene, false if not.
1819
*/
1920
module.exports = 'destroy';

0 commit comments

Comments
 (0)