Time for action – counting the lives
Tracking the lives left in the game keeps the player updated on how much sooner it will be till the game is over. To count the remaining lives in the game, perform the following steps:
Set up the function called
livesCount()
:local livesCount = function()
Display the text for lives every time the number is decremented:
gameLives = gameLives - 1 livesText.text = "Lives: " .. gameLives livesText.xScale = 0.5; livesText.yScale = 0.5 --> for clear retina display text livesText.x = (480 - (livesText.contentWidth * 0.5)) - 15 livesText.y = 15 print(gameLives .. " eggs left") if gameLives < 1 then callGameOver() end end
What just happened?
The livesCount()
function is a separate function that updates gameLives
. It makes sure that you're aware that gameLives = gameLives – 1
. This decreases the set value instantiated in the beginning of the code. When gameLives
changes values, it displays the update...