Tracking the lives left in the game keeps the player updated on how much sooner it will be until the game is over.
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
livesCount()
is a separate function that updates gameLives
. It makes sure that you're aware that gameLives = gameLives – 1
. This decreases the set value instantiated at the beginning of the code. When gameLives
changes values, it displays the update through livesText
. The print
statement is used towards the end of the...