2

I tried adding my own methods to the Tween class to pause/resume all tweens. This is what I have:

createjs.Tween.pauseAllTweens = function() 
{
    for ( var i = 0, tweenObj; tweenObj = createjs.Tween._tweens[i++]; )
        tweenObj.setPaused(true);
};

createjs.Tween.resumeAllTweens = function() 
{
    for ( var i = 0, tweenObj; tweenObj = createjs.Tween._tweens[i++]; )
        tweenObj.setPaused(false);
};

But I'm not getting the expected results. Can anyone clue me on how to pause all tweens, then resume them without having to pause the Ticker?

1
  • i just set framerate=0
    – zb'
    Oct 29, 2019 at 12:11

3 Answers 3

3

There is a simpler way to pause all of the tweens when using TweenJS from CreateJS ...

createjs.Ticker.paused = true; // pauses every tween

createjs.Ticker.paused = false; // un-pauses/resumes all of the tweens

1

Setting a tween to paused will remove it from the _tweens array. You are better off storing the tweens you create in your own array, and pause/resuming them there.

An approach that would work would be to iterate the _tweens array in reverse when you pause them, and store the tweens temporarily, so you can resume them later.

1

Ahh, yes... that helped me. Here is what I did:

var pausedTweenObjs = [];

createjs.Tween.pauseAllTweens = function() 
{
    var i = 0, 
        tweenObjs = createjs.Tween._tweens.slice().reverse(), 
        tweenObj;

    for ( ; tweenObj = tweenObjs[i++]; )
    {
        pausedTweenObjs.push(tweenObj);
        tweenObj.setPaused(true);
    }
};

createjs.Tween.resumeAllTweens = function() 
{
    var i = 0, tweenObj;

    for ( ; tweenObj = pausedTweenObjs[i++]; )
        tweenObj.setPaused(false);

    pausedTweenObjs.length = 0;
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.