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 – setting up the timer


We'll need to create a couple of functions that activate the countdown and also stop at 0 seconds when the game is over:

  1. Set up the timer countdown for the game with a local function called myTimer():

    local myTimer = function()
  2. Increment the seconds for the timer countdown by 1. With the counter text object, display the time using numSeconds. Print out numSeconds to see the countdown in the terminal window:

      numSeconds = numSeconds - 1
      counter.text = "Time: " .. tostring( numSeconds )
      print(numSeconds)
  3. Create an if statement for when the timer runs out or if all the stars are gone. Within the block, cancel the timer and call callGameOver() to end the round. Close the myTimer() function with end:

      if numSeconds < 1 or stars.numChildren <= 0 then
        timer.cancel(timerInfo)
        panda:pause()
        restartTimer = timer.performWithDelay( 300, function() callGameOver(); end, 1 )
      end
    
    end
  4. Initiate the myTimer() function with a new local function called...