Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By : Michelle M Fernandez
Book Image

Corona SDK Mobile Game Development: Beginner's Guide

By: Michelle M Fernandez

Overview of this book

Table of Contents (19 chapters)
Corona SDK Mobile Game Development Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – pausing the game


It's more than just making a button; it's also pausing all the action on screen, including physics and timers by performing the following steps:

  1. Add in the local pauseBtn and local pauseBG variables where all the other variables are initialized near the beginning of the code. Preload the btnSound audio after gameOverSound near the top of the script:

    -- Place near other game variables
    local pauseBtn
    local pauseBG
    
    -- Place after gameOverSound
    local btnSound = audio.loadSound( "btnSound.wav" )
  2. Within the hud() function and after the scoreText chunk, create another function that will run the event for the pause button. Call the onPauseTouch(event) function. Pause the physics in the game by setting gameIsActive to false and have the pause elements appear on screen:

        local onPauseTouch = function( event )
          if event.phase == "release" and pauseBtn.isActive then
            audio.play( btnSound )
    
            -- Pause the game
    
            if gameIsActive then
    
         ...