Cover by Michelle M. Fernandez

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Time for action – pausing the game

It's more than just making a button, it's also pausing all the action onscreen, including physics and timers.

  1. Add in the variables local pauseBtn and local pauseBG 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 thehud() function and after the scoreText chunk, create another function that will run the event for the pause button. Call the function onPauseTouch(event). Pause the physics in the game by setting gameIsActive to false and have the pause elements appear ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required