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?

gregmax17
  • 53
  • 1
  • 9

3 Answers3

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.

Lanny
  • 11,244
  • 1
  • 22
  • 30
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;
};
gregmax17
  • 53
  • 1
  • 9