Jump to content

Tween callback being called multiple times


Meowts
 Share

Recommended Posts

Six times, to be exact. Here's what I'm doing:

//Chained tweenvar tween = this.game.add.tween(player.player).to({x: this.chosenOne.x, y: this.chosenOne.y}, 1500, Phaser.Easing.Quadratic.InOut, true, 0, 0).to({x: this.chosenSplit.x, y: this.chosenSplit.y}, 1500, Phaser.Easing.Quadratic.InOut, true, 0, 0).to({x: point.x, y: point.y}, 1500, Phaser.Easing.Quadratic.InOut, true, 0, 0);	//Add handler to the last child of the chaintween._lastChild.onComplete.add(this.showError, this);	

this.showError() ends up being called 6 times. Is there a better way of assigning a handler for when the last tween is completed?

Link to comment
Share on other sites

Have you tried:

this.game.add.tween(player.player)    .to({x: this.chosenOne.x, y: this.chosenOne.y}, 1500, Phaser.Easing.Quadratic.InOut, true, 0, 0)    .to({x: this.chosenSplit.x, y: this.chosenSplit.y}, 1500, Phaser.Easing.Quadratic.InOut, true, 0, 0)    .to({x: point.x, y: point.y}, 1500, Phaser.Easing.Quadratic.InOut, true, 0, 0)    .onComplete.addOnce(this.showError, this);// notice I used .addOnce and included it in the chain instead of using a private var.
Link to comment
Share on other sites

Cool, thanks for that advice! Funny, I had a few different tweens in different situations where I had defined onComplete that way, and it wasn't until I fixed all of them that the handler was being called once. Good indication I was doing it wrong XD

Link to comment
Share on other sites

here is an example on how to chain tweens and make the oncomplete callback (which everyone would expect to be fired onComplete of the LAST tween not the first) be fired at the end of the chain.

var ascent = game.add.tween(body.sprite.scale).to({x:max,y:max}, upTime, Phaser.Easing.Sinusoidal.Out)var descent = game.add.tween(body.sprite.scale).to({x:originalScale,y:originalScale}, downTime, Phaser.Easing.Sinusoidal.In)descent.onComplete.add(function(){    do something });ascent.chain(descent).start();
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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