createjsanimate-cctweenjs

loop param not working as expected


I have a single clip on the stage with an instance name of testShape. In frame 1 I have the following code:

createjs.Tween.get(this.testShape, {loop:true}).to({y:240}, 1000);

When I run this it loops infinitely as expected but what I want is for it to loop three time then stop and fire a complete event. The docs say that the loop param...

Indicates the number of times to loop. If set to -1, the tween will loop continuously.

Which suggests I should be able to set {loop: 3} to achieve my desired result but any number value other than 0 just causes it to loop endlessly.

Can anyone advise on what I'm doing wrong or how to make a Tween loop n times before completing?

Cheers all


Solution

  • It looks like TweenJS 0.6.2 and earlier used a Boolean value for loops, so while you can set it to true or false, you can not put it as a number of loops. If you set it to a number, it will be converted to true.

    createjs.Tween.get(obj, {loop:true}).to(…).to(…);
    

    This behaviour was updated in version 1.0.0 of TweenJS, in September, 2017.

    createjs.Tween.get(obj, {loop:3}).to(…).to(…);
    

    I am glad you found a solution:

    I got it working in the end by making each tween set up the next as it completes.