Jump to content

tween onCompleteCallback?


FelixNemis
 Share

Recommended Posts

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 me

TypeError: tween.onUpdateCallback is not a function @ http://localhost/phaserProject/:240

tween in this case being a tween I got with

var 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 :P

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 weeks later...

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

  • 1 year later...

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?

 
Tnx
Luka
Link to comment
Share on other sites

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

  • 2 years later...
  • 8 months later...
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

 Share

  • Recently Browsing   0 members

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