CornishCuc Posted October 3, 2013 Share Posted October 3, 2013 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? AS3: 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 More sharing options...
GreenSock Posted October 3, 2013 Share Posted October 3, 2013 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: Don't shut the frame rate down. Or force the ticker to update it before you resumeAll(), so just add this before the resumeAll(): TweenMax.ticker.dispatchEvent(new Event("enterFrame")); 1 Link to comment Share on other sites More sharing options...
CornishCuc Posted October 3, 2013 Author Share Posted October 3, 2013 Fantastic, worked like a charm AND a speedy response. Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now