Loop part of a tween with tween.js

半城伤御伤魂 提交于 2019-12-22 08:54:47

问题


Here's a simple tween in Tween.js. A simple loop happens after an interval.

cjs.Tween.get(mySymbol).wait(50).to({x:10}).to({x:0});

Is there a way to make it repeat say 5 times after the interval, without repeating the interval?

By adding loop:true I can make it loop but the loop would include the wait().

cjs.Tween.get(mySymbol, {loop:true}).wait(50).to({x:10}).to({x:0});

Is there any way to add tweens to the timeline sequentially in Tween.js?


回答1:


Answer courtesy of Grant Skinner:

cjs.Tween.get(ball).wait(1000).play(
    cjs.Tween.get(ball,{paused:true, loop:true})
    .to({x:450},1000)
    .to({x:50},1000)
  );



回答2:


To loop 5 times you can use a callback:

var tl = new createjs.Timeline();

tl.addTween(createjs.Tween.get(mySymbol).wait(500).call(loop, [mySymbol, 0], this));

var i;
var loopMax = 5;

function loop(target, initI){

    if (initI != null) {
        i = initI;
    } else {
        i++
    }

    if (i < loopMax) createjs.Tween.get(target).to({x:450},1000).to({x:50},1000).call(loop, [target]);

}


来源:https://stackoverflow.com/questions/16650528/loop-part-of-a-tween-with-tween-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!