Meowts Posted October 14, 2014 Share Posted October 14, 2014 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 More sharing options...
xerver Posted October 14, 2014 Share Posted October 14, 2014 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. Behzat 1 Link to comment Share on other sites More sharing options...
rich Posted October 14, 2014 Share Posted October 14, 2014 The moment you start adding things to, or manipulating private properties you should be questioning exactly why you had to do this. It's rarely required and/or leads to the desired outcome. Link to comment Share on other sites More sharing options...
Meowts Posted October 15, 2014 Author Share Posted October 15, 2014 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 More sharing options...
Meowts Posted October 15, 2014 Author Share Posted October 15, 2014 Oh yeah, forgot to mention though (duh), the onComplete handler, though being called once, is being called after the first tween animation. Link to comment Share on other sites More sharing options...
valueerror Posted October 15, 2014 Share Posted October 15, 2014 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 More sharing options...
Recommended Posts