How to detect Tween.js animation finished?

Stephan Ahlf picture Stephan Ahlf · Feb 5, 2015 · Viewed 9k times · Source

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(); 
            },

Answer

joews picture joews · Feb 5, 2015

Provide an onComplete function:

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

Docs