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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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