Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

8. Operation Storyboard > Time for action – pausing the game

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 the hud() 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 on screen.
        local onPauseTouch = function( event )
          if event.phase == "release" and pauseBtn.isActive then
   btnSound )
            -- Pause the game
            if gameIsActive then
              gameIsActive = false
              local function pauseGame()
                        timer.pause( startDrop )
                        print("timer has been paused")
                    timer.performWithDelay(1, pauseGame)
              -- SHADE
              if not shade then
                shade = display.newRect( 0, 0, 570, 380 )
                shade:setFillColor( 0, 0, 0, 255 )
                shade.x = 240; shade.y = 160
                gameGroup:insert( shade )          


You are currently reading a PREVIEW of this book.


Get instant access to over $1 million worth of books and videos.


Start a Free 10-Day Trial

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint