how to know then end of 2 tween ?



  • my code:

    tween = FlxTween.tween(sprite, {x:50, y:50}, 5).then(FlxTween.tween(sprite, {x:100, y:50}, 10));

    if i try: tween.finished the result is true after 5 secondes, but i want to know when the 2 tweens are finished.

    how to do ?



  • @wazou
    You can use the onComplete callback in the second tween, like this.

    tween = FlxTween.tween(sprite, {x:50, y:50}, 5).then(FlxTween.tween(sprite, {x:100, y:50}, 10, { onComplete: tweenComplete } ));
    
    ...
    
    private function tweenComplete(tween:FlxTween):Void
    {
    	trace("tween complete!");
    }
    


  • thanks for this solution, now it,s ok for me. After tween complete i try to do 'tween = null' but the tween always exist.

    Do you know a solution to do it ?



  • The solution is TADA:

    private function tweenComplete(tween:FlxTween):Void
    {
    trace("tween complete!");
    cleanTween();
    }

    public function cleanTween():Void
    {
    tween = null;
    }



  • Another way to do it

    tween = FlxTween.tween(sprite, {x:50, y:50}, 5).then(FlxTween.tween(sprite, {x:100, y:50}, 10, { onComplete: function(_){
    trace("the end");
    tween = null;
     } }));
    

Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.