Jump to content

pendingDestroy doesn't work on killed objects


Andrey Denisov
 Share

Recommended Posts

I faced the following problem.

I have a sprite, which is a part of Phaser.Group. When I kill the sprite using a "kill" method and then mark it with the "pendingDestroy = true;", the sprite is not being destroyed at all.

If I understand the idea of using "pendingUpdate" the game engine must destroy the object automatically in "preUpdate" method. I checked that the Phaser.Group calls for the "preUpdate" method of its children even if they are not alive.

However, the "preUpdate" method of the Phaser.Sprite class seems to be very tricky.

image.png.b6d6081aeb5dab7a1104b3fe624cab5a.png 

This pendignDestroy is processed only in Phaser.Component.Core.preUpdate, so if one of the functions listen in line 49139 returns false the pendingUpdate won't be processed. Unfortunately, this is exactly what the first method does (Phaser.Component.PhysicsBody.preUpdate).


image.png.363a4b8654080b2f8a843957fe3b01f1.png

For non existing sprites (i.e. killed sprites) preUpdatePhysics() will always return false. Hence, the pendingDestroy  flag won't be processed in Phaser.Component.Core.preUpdate.

image.png.0ae4767a040730b687f9dc5acffe22a2.png

 

P.S.  I can't use the "destroy" method directly. For example, when I check for collisions between two groups with more than one alive object in each group, destroying objects can cause some errors (still trying to find out the reason of it).

Link to comment
Share on other sites

Pending a bug fix, I would just overwrite the method:

Phaser.Sprite.prototype.preUpdate = function () {

    if (this.pendingDestroy)
    {
        this.destroy();
        
        return false;
    }

    if (!this.preUpdatePhysics() || !this.preUpdateLifeSpan() || !this.preUpdateInWorld())
    {
        return false;
    }

    return this.preUpdateCore();

};

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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