Jump to content

Anyone had any problems with game.tweens.removeFrom(object) ?


clark
 Share

Recommended Posts

I am dealing a set of cards out into a grid which is fine, but I need to do some changes which allow me to interrupt this process and cancel it. 

 

On the deck I have a reset function which should go through each card, and remove the tween.  Then set the card to a point off screen directly. 

 

However, I am having some mixed results.   I cannot seem to cancel a tween:

 

 

This one appears to stop tweens, kind of, but the position of the card is ignored. For example if the tweening card was at x:200 y:200 then the card would stay there, and so card.x and card.y is apparently ignored.

for (i = 0; i < len; i++) {        card = this.gameDeck[i];        this.game.tweens.removeFrom(card);        card.x = spawnPoint.x;        card.y = spawnPoint.y;}

So then I was like hey, I know, Ill just tween these cards.  If Tweening is the only thing that is setting the position, then I will do this:
 

for (i = 0; i < len; i++) {         card = this.gameDeck[i];         this.game.tweens.removeFrom(card);         tween = this.game.add.tween(card);         tween.to({ x: this.spawnPoint.x, y: this.spawnPoint.y }, 0, Phaser.Easing.Elastic.Out, true, 0);}

But then, when I deal now, something weird happens, the cards dissapear once they complete.  So I was like hmm. What about is I keep reference to all tweens?
 

while (this.tweens.length > 0) {       var tween: Phaser.Tween = this.tweens.pop();       this.game.tweens.remove(tween);       tween = null;}for (i = 0; i < len; i++) {       card = this.gameDeck[i];       this.game.tweens.removeFrom(card);       tween = this.game.add.tween(card);       tween.to({ x: this.spawnPoint.x, y: this.spawnPoint.y }, 0, Phaser.Easing.Elastic.Out, true, 0);       this.tweens.push(tween);}

This seems to work as expected.  You can also comment out the removeFrom in the last example since it is superfluous.  Basically, I am working around it.

 

The question becomes then,  has anyone experience any problems with game.tweens.removeFrom(object) ?  Or is there something fundamental I do not understand? (in my own code base of course :P )

 

Thanks!

Link to comment
Share on other sites

When you call 'removeFrom' it sets a flag on the tween, 'pendingDelete', to true. It's then queued for deletion which happens in the next update, not immediately. So it's possible the tween is setting values on the sprite one last time, over-riding your new x/y positions - this all depends where the remoteFrom is being called from.

 

There's no difference between Sprite.x and Sprite.position.x - the first is an alias for the second.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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