Andrey Denisov Posted November 6, 2017 Share Posted November 6, 2017 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. 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). 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. 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 More sharing options...
samme Posted November 6, 2017 Share Posted November 6, 2017 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(); }; Andrey Denisov 1 Link to comment Share on other sites More sharing options...
samme Posted November 8, 2017 Share Posted November 8, 2017 phaser-ce/issues/399 Link to comment Share on other sites More sharing options...
Recommended Posts