Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Triggering onDestroy


brentstrandy
 Share

Recommended Posts

I'm having a hard time triggering onDestroy for my FreezeEffect object.

I've essentially set up an object that destroys itself after a few seconds. I've tested and confirmed that "destroyObject" is being called. But sometimes the game ends, the state transitions in the middle of the FreezeEffect, and the "onDestroy" method is never called. I was under the assumption that calling state.start('newState') destroys the Phaser objects in the previous state. Is that not true?

Example code:

// Freeze Effect
FreezeEffect = function (game) {
    ... constructor code ...
    ... create tween to fade freeze effect ...

    // Call function to destroy the freeze effect when the tween finishes
    tween.onComplete.add(this.destroyObject, this);

    // Slow down time
    game.time.slowMotion = 2.0;
};

FreezeEffect.prototype = Object.create(Phaser.Group.prototype);
FreezeEffect.prototype.constructor = FreezeEffect;

FreezeEffect.prototype.destroyObject = function() {
    // Put time at normal speed
    this.game.time.slowMotion = 1.0;

    this.parentGroup.destroy(true, false);
    this.freezeSFX.destroy();
    // Destroy the object and free memory
    this.destroy(true, false);
};

FreezeEffect.prototype.onDestroy = function() {
    // Put time at normal speed
    this.game.time.slowMotion = 1.0;
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...