How to manage pause/resume states in games?

Hi,

I’m looking best practices for pause/resume a game which includes stop/cancel/resume timers and transitions. Any help/advice/code appreciated.

ldurniat

Hi!

Surely I would do two methods: “gamePause”, “gameResume”.

Then as regards timers and transactions depends, do you want to block everything together?

In this case, for the transitions just invoke the function without passing some parameters:

tranistion.pause()

https://docs.coronalabs.com/api/library/transition/pause.html

While the timers do not support this. So I should make a form to manage creation and pause. Some time ago I found something interesting but I still could not prove it:

However, it is not always necessary to pause everything so I would make a module that manages ids and tags so that we can group timers and transition by categories.

Transitions

Timers: timer2.*
The default timer.* library does not support tags, but timer2 does: http://www.jasonschroeder.com/2015/02/25/timer-2-0-library-for-corona-sdk/

(If you are  using a recent copy of SSK2, timer 2 is already present and replacing timer.*)

Physics

  • physics.pause() to pause
  • physics.start() to resume

enterFrame and other listeners

You can gate enterFrame and other listeners by using:

  • a global flag: _G.gameIsPaused  -OR- 
  • a common module with a flag: common.gameIsPaused

You simply check for this flag in key logic that should respect the ‘is paused’ state.

With these four solutions, you can selectively pause and resume your game objects and logic as needed.
 
 
Finally,  I am working on a few products and among them is a ‘frameworks’ collection.  This collection will include a set of example game modules with all of these features demonstrated:

  • init()
  • create() and destroy()
  • start() and restart()
  • stop() and continue() 
  • pause() and resume()

The frameworks collection isn’t quite ready, but I’ll announce when it is.
 

@roaminggamer: As always your answer is clear and easy to follow:) Thanks.

Hi!

Surely I would do two methods: “gamePause”, “gameResume”.

Then as regards timers and transactions depends, do you want to block everything together?

In this case, for the transitions just invoke the function without passing some parameters:

tranistion.pause()

https://docs.coronalabs.com/api/library/transition/pause.html

While the timers do not support this. So I should make a form to manage creation and pause. Some time ago I found something interesting but I still could not prove it:

However, it is not always necessary to pause everything so I would make a module that manages ids and tags so that we can group timers and transition by categories.

Transitions

Timers: timer2.*
The default timer.* library does not support tags, but timer2 does: http://www.jasonschroeder.com/2015/02/25/timer-2-0-library-for-corona-sdk/

(If you are  using a recent copy of SSK2, timer 2 is already present and replacing timer.*)

Physics

  • physics.pause() to pause
  • physics.start() to resume

enterFrame and other listeners

You can gate enterFrame and other listeners by using:

  • a global flag: _G.gameIsPaused  -OR- 
  • a common module with a flag: common.gameIsPaused

You simply check for this flag in key logic that should respect the ‘is paused’ state.

With these four solutions, you can selectively pause and resume your game objects and logic as needed.
 
 
Finally,  I am working on a few products and among them is a ‘frameworks’ collection.  This collection will include a set of example game modules with all of these features demonstrated:

  • init()
  • create() and destroy()
  • start() and restart()
  • stop() and continue() 
  • pause() and resume()

The frameworks collection isn’t quite ready, but I’ll announce when it is.
 

@roaminggamer: As always your answer is clear and easy to follow:) Thanks.