让timelineMax等待一个事件,同时无限循环

时间:2014-06-01 13:19:00

标签: greensock tweenmax

我如何有一个时间轴,无限循环一个tweenmax动画,直到一个事件被触发,然后转移到下一个补间?

timeline = new TimelineMax();
timeline.append(TweenMax.to(targetReel, .3, {y: -(Main.iconH >> 1)}));

//keep spinning infinitely. Not firing the onComplete function till I got a result
timeline.append(TweenMax.to(targetReel, 2, {y: newNumber, ease: Linear.easeNone, onComplete: somefunction}));

//got a result/dispatch event, continue timeline
timeline.append(TweenMax.to(targetReel, 1 + (i * .6), {y: 0, ease: Back.easeOut, onStart: somefunction, onComplete: endAnimation}));

1 个答案:

答案 0 :(得分:0)

你可以将它放在一个函数中,你可以在不使用时间轴的情况下使用它并将一些事件更改重复为false


    var repeating = true;
    TweenMax.to(targetReel, .3, {y: -(Main.iconH >> 1)},onComplete: repeat);

    function repeat(){
        if (repeating){
            //keep spinning infinitely. Not firing the onComplete function till I got a result
            TweenMax.to(targetReel, 2, {delay: .3, y: newNumber, ease: Linear.easeNone, onComplete: repeat});
        }else{ // repeating == false
            TweenMax.to(targetReel, 2, {y: newNumber, ease: Linear.easeNone, onComplete: doneRepeating});
        }
    }

    function doneRepeating(){
        //got a result/dispatch event, continue timeline
        TweenMax.to(targetReel, 1 + (i * .6), {y: 0, ease: Back.easeOut, onStart: somefunction, onComplete: endAnimation});
    }


    // have some event change repeating to false;