Skip to content

Commit

Permalink
Merge pull request #5717 from rexrainbow/destroy-from-scene
Browse files Browse the repository at this point in the history
Add 'fromScene' parameter in GameObject.destroy() method, and DESTROY event
  • Loading branch information
photonstorm authored May 26, 2021
2 parents c8cc337 + 07ff5de commit 5552079
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/gameobjects/GameObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,21 +821,25 @@ var GameObject = new Class({
* @method Phaser.GameObjects.GameObject#destroy
* @fires Phaser.GameObjects.Events#DESTROY
* @since 3.0.0
*
* @param {boolean} fromScene - True if this Game Object is destroyed from scene, false if not.
*/
destroy: function ()
destroy: function (fromScene)
{
// This Game Object has already been destroyed
if (!this.scene || this.ignoreDestroy)
{
return;
}

if (fromScene === undefined) { fromScene = false; }

if (this.preDestroy)
{
this.preDestroy.call(this);
}

this.emit(Events.DESTROY, this);
this.emit(Events.DESTROY, this, fromScene);

this.removeAllListeners();

Expand Down
1 change: 1 addition & 0 deletions src/gameobjects/events/DESTROY_EVENT.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
* @since 3.0.0
*
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object which is being destroyed.
* @param {boolean} fromScene - True if this Game Object is destroyed from scene, false if not.
*/
module.exports = 'destroy';

0 comments on commit 5552079

Please sign in to comment.