Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect Tween.js animation finished?

I am using this code to animate camera in scene using tween.js Does there a exists any done or finshed event?

            tween : function (target){
                var position = camera.position;
                var tween = new TWEEN.Tween(position).to(target, 1800);

                tween.onUpdate(function(){
                    camera.position.x = position.x;
                    camera.position.y = position.y;
                    camera.position.z = position.z;
                    if (android){
                        camera.lookAt(android.position)
                    }
                });
                tween.easing(TWEEN.Easing.Bounce.Out);
                tween.start(); 
            },
like image 324
Stephan Ahlf Avatar asked Feb 05 '15 12:02

Stephan Ahlf


2 Answers

Provide an onComplete function:

tween.onComplete(function() {
  console.log('done!')
});

Docs

like image 138
joews Avatar answered Nov 08 '22 16:11

joews


As of April 2018, .onComplete doesn't exist in the docs. Rather you can use the .call function then pass a custom function.

   createjs.Tween.get(target).to({alpha:1}, 1000).call(handleComplete);
    function handleComplete() {
        //Tween complete
    }

See docs: https://www.createjs.com/docs/tweenjs/modules/TweenJS.html

like image 42
nycdanie Avatar answered Nov 08 '22 16:11

nycdanie