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 – changing screens after the game is over


Now that we have renamed our game file, let's add in a scene transition so that our game is not stuck at the Game Over screen once game play is over. To change the screen, perform the following steps:

  1. In our maingame.lua file, add in a new variable called local menuBtn, where all the other variables are initialized in the beginning of the code. Inside the callGameOver() function, add the following lines after the highScoreText code:

        local onMenuTouch = function( event )
          if event.phase == "release" then
            audio.play( btnSound )
            composer.gotoScene( "mainmenu", "fade", 500  )
    
          end
        end
    
        menuBtn = ui.newButton{
          defaultSrc = "menubtn.png",
          defaultX = 60,
          defaultY = 60,
          overSrc = "menubtn-over.png",
          overX = 60,
          overY = 60,
          onEvent = onMenuTouch,
          id = "MenuButton",
          text = "",
          -- Can use any font available per platform
          font = "Helvetica",...