Jump to content


Strange problem with TweenMax and Framerate

Recommended Posts

I came across a peculiar problem with Greensock today whilst playing with a 'pause' function for a game. The purpose of the two following functions are:


When the pause button (in this case it's a sprite named it 'menu') is pressed it causes all existing TweenMax instances to pause in place. It also sets the stage's framerate to 0, making all display objects pause in place. I've been told this is the best method pausing the game.


When the button is pressed again, it should resume all the tweens from where they were initially paused. However, the problem is these tweens jump to their finishing position regardless of when they were paused, so when I resume the game the tween finishes abruptly.


The strange thing is, if the framerate isn't changed (resumes at 30, for example), the Tweens resume from where they originally paused. Am I just being stupid and missing something obvious? 



protected function pauseGame(event:MouseEvent):void
menu.removeEventListener(MouseEvent.CLICK, pauseGame);
menu.addEventListener(MouseEvent.CLICK, resumeGame);
TweenMax.pauseAll(true, true);
stage.frameRate = 0;

protected function resumeGame(event:MouseEvent):void
menu.removeEventListener(MouseEvent.CLICK, resumeGame);
menu.addEventListener(MouseEvent.CLICK, pauseGame);
TweenMax.resumeAll(true, true);
stage.frameRate = 30;
Link to comment
Share on other sites

Yeah, when you completely shut down the frame rate, there's no chance for the central ticker to update its time (you're basically shutting down the entire engine), so when you resume everything it still has the OLD time in there. On the next tick, it'll update its time and things will jump forward. There are two solutions:

  1. Don't shut the frame rate down. 
  2. Or force the ticker to update it before you resumeAll(), so just add this before the resumeAll(): TweenMax.ticker.dispatchEvent(new Event("enterFrame"));
  • Like 1
Link to comment
Share on other sites

Fantastic, worked like a charm AND a speedy response.


Thank you!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.