How to pause the game?

2 votes · 0 comments

From patrick @ Zipline:

Forum thread here:

The way to pause the game is to swap out the root action in the action tree. Anything that gets an update in Moai inherits from MOAIAction. This includes all the helper animations. If you don't explicitly give an action a parent action (to get updates from), it will be automatically attached to the root action.

You can get at the root action by calling MOAIActionMgr.getRoot (). You can also replace the root with a call to MOAIActionMgr.setRoot ().

So the easiest way to pause your game is to do something like:

oldRoot = MOAIActionMgr.getRoot () -- get the root

MOAIActionMgr.setRoot () -- clear out the old root; will be automatically recreated

thread = MOAIThread.new ()

thread:run ( doPaused ) -- start a new thread to handle input and wait for unpause; if you don't do this the game will end here!

From inside of doPause, you'll then just restore the original root by calling setRoot ( oldRoot ) and exiting your coroutine.

That's the idea, anyway. Try it out and let me know if it gives you any trouble.

raw ·
copy
· download
oldRoot = MOAIActionMgr.getRoot () -- get the root MOAIActionMgr.setRoot () -- clear out the old root; will be automatically recreated thread = MOAIThread.new () thread:run ( doPaused ) -- start a new thread to handle input and wait for unpause; if you don't do this the game will end here!

Be the first to comment

Sign in with OpenID