It's more than just making a button, it's also pausing all the action onscreen, including physics and timers.
Add in the variables
local pauseBtn
andlocal pauseBG
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 the functiononPauseTouch(event)
. 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 gameIsActive...