We're going to execute the timer for the egg so they can start dropping them on the screen.
Create a local function called
eggTimer()
and usetimer.performWithDelay
to drop an egg every 1 second (1000
milliseconds) repeatedly. UseeggDrop()
to activate the drop.local eggTimer = function() startDrop = timer.performWithDelay( 1000, eggDrop, 0 ) end
Within the first
if
statement in theonEggCollision()
function, cancel the timer using thetimerID
,startDrop
. Add the statementif
gameLives < 1
to stop the eggs from falling.if gameLives < 1 then timer.cancel( startDrop ) print("timer cancelled") end
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 = timer.performWithDelay( 1000, eggDrop, 0 )
.
Backtracking to onEggCollision...