Finally! – A function for Pausing All Timers in Corona SDK

Any game developers using Corona SDK will eventually run into a struggle when it comes to implementing a pause menu. Since the goal is to “pause” all objects on the screen, four different “to-dos” need to occur:

  • physics.pause() for any objects that utilize the physics engine.
  • transition.pause() for all object transitions in play.
  • Pausing animations of any relevant objects on screen. If implemented correct, this should be as simple as parsing a display group.
  • Pausing all timers that are active.

While the first three can be relatively easy to implement, the fourth bullet point seems to be a common struggle experienced in the Corona community. The timer object can only pause individual timers (assuming you have the timer readily available). It’s beyond me why Corona Labs failed to implement an all-encompassing timer pause similar to how they handle physics and transitions, but perhaps there is a reason I’m unaware of.

In order to alleviate this, I’ve developed a lua script that adds additional functions to the existing timer class which allows you to pause and resume all timer objects. You can download the code file here. After referencing the file in your code, the following new functions should be used in your application:

  • timer:createTimer(delay, listener, iterations) – Replace all instances of timer.performWithDelay with this function.
  • timer:destroyTimer(id) – Replace all instances of timer.cancel with this function.
  • timer:pauseAllTimers() – New function to pause all timers that were created through the createTimer method.
  • timer:resumeAllTimers() – New function to resume all paused timers that were created through createTimer.

I’ve been using this code file and it’s worked fairly well for my game, Alley Avenger. If you have any suggestions for improvements, let me know! AnomalyArtsGames@gmail.com

 

One thought on “Finally! – A function for Pausing All Timers in Corona SDK

Leave a comment