Skip to content

Commit baeca90

Browse files
committed
Add destroy event
Add destroy event of gameobject, also add a checking to prevent re-enter this destroy function.
1 parent 1f8d0c8 commit baeca90

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/gameobjects/GameObject.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ var GameObject = new Class({
320320
*/
321321
destroy: function ()
322322
{
323+
// this gameobject had been destroyed
324+
if (this.scene === undefined)
325+
{
326+
return;
327+
}
328+
323329
if (this.preDestroy)
324330
{
325331
this.preDestroy.call(this);
@@ -357,6 +363,8 @@ var GameObject = new Class({
357363

358364
this.scene = undefined;
359365

366+
this.emit('destroy');
367+
360368
this.removeAllListeners();
361369
}
362370

0 commit comments

Comments
 (0)