Jump to content

onComplete on chained tweens


Recommended Posts



I want to execute a function at the end of a tweens chain.


Here is an example of what I did :

var currentTween = null;var prevTween = null;myGroup.forEach(function (obj){    currentTween = game.add.tween(sprite).to({ x: obj.x, y: obj.y }, 100, Phaser.Easing.Linear.None);    if(prevTween){        prevTween.chain(currentTween);    } else {        sprite.movementAnimation = currentTween;    }    prevTween = currentTween;});/* add here the onComplete callback */sprite.movementAnimation.start();

My animation works like a charm.


First I tried :

sprite.movementAnimation.onComplete.add(myFunction, this);

=> myFunction executes at the end of the first tween.


Then I tried :

sprite.movementAnimation.onChildComplete.add(myFunction, this);

=> myFunction is never called but I have no errors.


Then I tried :

sprite.movementAnimation._lastChild.onComplete.add(myFunction, this);

=> I get the error "Uncaught TypeError: Cannot read property 'onComplete' of undefined" (in fact console.log(sprite.movementAnimation._lastChild) returns undefined)



Could one of you explain me what I did wrong or show me another way to achieve what I want to do ?





Link to comment
Share on other sites


  • Recently Browsing   0 members

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