Jump to content

Best way to destroy a group from an event of a sprite within the group


slashware
 Share

Recommended Posts

Hello all!

 

I have a room based game, (http://slashland.co/ananiasTest) every time the player clicks a door the player sprite is tween-moved to the door, then the spritegroup containing the sprites of the room is destroyed (including the door sprite).

 

The problem I'm having is that some times (not every time), there seems to be an issue with the engine trying to invoke a signal for a mouse over event, and failing because the sprite no longer has the _bindings object ( http://imgur.com/UaxQcyw )

 

What do you think is the best way to do this? I'm destroying the sprite group in the mouse up event of the sprite, but this doesn't seem to ensure this kind of conflicts.

 

I'm using the latest phaser but I think this problem happened before too (but not as frequent) with phaser 1.1.6

Link to comment
Share on other sites

It seems like the sprite is in a zombie state which makes it go over the "am I dead" validation here:

 

 /**    * Internal method handling the pointer out event.    * @method Phaser.InputHandler#_pointerOutHandler    * @private    * @param {Phaser.Pointer} pointer    */    _pointerOutHandler: function (pointer) {        if (this.sprite === null)        {            //  Abort. We've been destroyed.            return;        }        this._pointerData[pointer.id].isOver = false;        this._pointerData[pointer.id].isOut = true;        this._pointerData[pointer.id].timeOut = this.game.time.now;        if (this.useHandCursor && this._pointerData[pointer.id].isDragged === false)        {            this.game.canvas.style.cursor = "default";            this._setHandCursor = false;        }        if (this.sprite && this.sprite.events)        {            this.sprite.events.onInputOut.dispatch(this.sprite, pointer); // From here downward, there are no bindings anymore but it goes on to check them        }    },

Thought I'd also say that since it's a mouseover event it happens a lot of times, until the next sprite group is destroyed :/

Link to comment
Share on other sites

yay! I'm now able to reproduce this!

 

The sprite has both a mousedown and mouseup event, this is hapening when the mouse up event is triggered but the sprite has been "destroyed" already, it seems like it's not being able to accurate know this has happened.

 

To reproduce the issue just click on a door (leave mouse down) then release the button once you are in a new room.

 

I'll look into a solution for this, but might be good idea to incorporate this validation?

Link to comment
Share on other sites

I think I'll have to go ahead and work out a patch for this, unless maybe I'm missing something obvious and I'm misusing the library? can anyone please check?

 

I don't think I'm doing anything weird, I'm just adding these events after creating the sprite:

var sprite = this.phaser.add.sprite(x * 32, y*32, spriteId, frame, this.mapLayer);this.currentSpriteGroup.add(sprite);sprite.events.onInputDown.add(this.interactDoorBridge, this);sprite.events.onInputUp.add(this.interactDoorBridgeUp, this);
And then in the interactDoorBridgeUp I'm doing
this.currentSpriteGroup.destroy(true);
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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