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:
Add in the
local pauseBtn
andlocal pauseBG
variables where all the other variables are initialized near the beginning of the code. Preload thebtnSound
audio aftergameOverSound
near the top of the script:-- Place near other game variables local pauseBtn local pauseBG -- Place after gameOverSound local btnSound = audio.loadSound( "btnSound.wav" )
Within the
hud()
function and after thescoreText
chunk, create another function that will run the event for the pause button. Call theonPauseTouch(event)
function. Pause the physics in the game by settinggameIsActive
tofalse
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 ...