FelixNemis Posted October 10, 2013 Share Posted October 10, 2013 Ok, so I'm using a tween to rotate an abject between the four cardinal directions on arrow key press,and I'm using the on complete callback to set a boolean to allow rotating again once it's done. The problem is whenever I try to use the onCompleteCallback function of a tween it gives meTypeError: tween.onUpdateCallback is not a function @ http://localhost/phaserProject/:240tween in this case being a tween I got withvar tween = game.add.tween(rod);In a keyboard check in the update function. Any other function of the tween works except the callback functions. (I tried onUpdateCallback, same story)I resorted to using tween._onCompleteCallback = doneTurning;which works, but I'd rather do it the right way Link to comment Share on other sites More sharing options...
rich Posted October 10, 2013 Share Posted October 10, 2013 Two options:tween.onCompleteCallback(doSomething);function doSomething () {// ...}This method passes in a reference to the function, but has no context so you'll probably find loses scope. I would however do this:tween.onComplete.add(doSomething, this);function doSomething () {// ...}Which uses the Signals system built into Phaser and will retain scope. hoskope and wipster 2 Link to comment Share on other sites More sharing options...
FelixNemis Posted October 11, 2013 Author Share Posted October 11, 2013 Thanks! Link to comment Share on other sites More sharing options...
claire Posted October 28, 2013 Share Posted October 28, 2013 Two options:tween.onCompleteCallback(doSomething);function doSomething () {// ...}This method passes in a reference to the function, but has no context so you'll probably find loses scope. I would however do this:tween.onComplete.add(doSomething, this);function doSomething () {// ...}Which uses the Signals system built into Phaser and will retain scope. I want to use chained tweens, but the onComplete is only call after the first tween complete.var tween = this.game.add.tween(spriteReady).to({ x: centerX }, 500, Phaser.Easing.Linear.None).to({ x:centerX }, 1000, Phaser.Easing.Linear.None).to({ x: this.game.world.width+spriteReady.width/2 }, 500, Phaser.Easing.Linear.None).start();tween.onComplete.add(this.theEnd, this)I want onComplete to call after all the tweens are complete, is there any way to do this? Link to comment Share on other sites More sharing options...
powerfear Posted October 28, 2013 Share Posted October 28, 2013 @claire try this: tween._lastChild.onComplete.add(this.theEnd, this); lucasfevi and ianmcgregor 2 Link to comment Share on other sites More sharing options...
claire Posted October 28, 2013 Share Posted October 28, 2013 @claire try this: tween._lastChild.onComplete.add(this.theEnd, this); It works!! Thanks!! Link to comment Share on other sites More sharing options...
lukaMis Posted November 1, 2014 Share Posted November 1, 2014 Hi. Is there a way to pass arguments in to function that is called as tween onComplete callback? Example: var t = this.add.tween(this.car).to({ x: this.carPosXEnd }, 1000, Phaser.Easing.Quadratic.Out, true);t.onComplete.add(this.addQuestion, this); but addQuestion needs parameters:addQuestion: function (_questionText) { this.question = this.add.text(this.questionPosX, this.questionPosY, _questionText, this.questionStyle); this.trafficLight.addChild(this.question); }Is there a way to add them as part of onComplete callback? TnxLuka Link to comment Share on other sites More sharing options...
lukaMis Posted November 1, 2014 Share Posted November 1, 2014 OK. Never mind. Found an answer. Anonymous function ftw!For anyone interested it is like this:var t = this.add.tween(this.car).to({ x: this.carPosXEnd }, 1000, Phaser.Easing.Quadratic.Out, true);t.onComplete.add(function () { this.addQuestion(this.questionText); }, this);Have a nice day. Link to comment Share on other sites More sharing options...
samme Posted September 9, 2017 Share Posted September 9, 2017 On 10/27/2013 at 8:55 PM, claire said: I want onComplete to call after all the tweens are complete, is there any way to do this? onComplete should work this way according to the current docs. Link to comment Share on other sites More sharing options...
andrefbr21 Posted May 30, 2018 Share Posted May 30, 2018 On 11/1/2014 at 11:45 AM, lukaMis said: OK. Never mind. Found an answer. Anonymous function ftw! For anyone interested it is like this: var t = this.add.tween(this.car).to({ x: this.carPosXEnd }, 1000, Phaser.Easing.Quadratic.Out, true);t.onComplete.add(function () { this.addQuestion(this.questionText); }, this); Have a nice day. You can use the last parameter to pass aditional parameters to the function, this way you dont need to use anonymous functions ex: t.onComplete.add(this.addQuestion, this, 0, this.questionText); Link to comment Share on other sites More sharing options...
Recommended Posts