最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to detect Tween.js animation finished? - Stack Overflow

programmeradmin1浏览0评论

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

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(); 
            },
Share Improve this question asked Feb 5, 2015 at 12:09 Stephan AhlfStephan Ahlf 3,4975 gold badges42 silver badges70 bronze badges 1
  • FYI for others while im lurking around tween.js posts - this snippet didn't need to set the position again in the onUpdate, it was already set by Tween at this point. It's just assigning its own values back to itself. – rtpHarry Commented Sep 26, 2018 at 8:45
Add a comment  | 

2 Answers 2

Reset to default 14

Provide an onComplete function:

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

Docs

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

发布评论

评论列表(0)

  1. 暂无评论