Reader small image

You're reading from  Corona SDK Mobile Game Development: Beginner's Guide

Product typeBook
Published inMar 2015
Publisher
ISBN-139781783559343
Edition1st Edition
Tools
Right arrow
Author (1)
Michelle M Fernandez
Michelle M Fernandez
Right arrow

Time for action – making the egg drop


We're going to execute the timer for the eggs, so that they can start dropping on the screen. To make the egg drop, perform the following steps:

  1. Create a local function called eggTimer() and use timer.performWithDelay to drop an egg every 1 second (1000 milliseconds) repeatedly. Use eggDrop() to activate the drop:

        local eggTimer = function()
          startDrop = timer.performWithDelay( 1000, eggDrop, 0 )
        end
  2. Within the first if statement in the onEggCollision() function, cancel the timer using the timerID and startDrop variables. Add the if gameLives < 1 statement then to stop the eggs from falling:

          if gameLives < 1 then
            timer.cancel( startDrop )
            print("timer cancelled")
          end

What just happened?

In order for the eggs to start dropping from the sky, we created a function called eggTimer(). It activates the eggDrop() function by letting an egg drop after 1000 milliseconds (1 second) every time infinitely using startDrop...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Corona SDK Mobile Game Development: Beginner's Guide
Published in: Mar 2015Publisher: ISBN-13: 9781783559343

Author (1)