I am working on a game that shows the amount of lives the player has on the top left corner. The problem is: if the player dies and wants to play again, the lives are not shown. The lives were created in scene:create and I knew that this would only show once. So, I tried moving it to scene:show(phase == “will”), but now, the player does not appear to lose lives, and they show on different scenes.
This is how they are created and removed:
Two forward declares:
local lives = {} -- table that will hold the lives object local livesCount = 4
For loop:
for i=1, livesCount do lives[i] = display.newImageRect("heart.png", 50, 50) lives[i].x = \_L + (i \* 65) - 25 lives[i].y = \_T + 50 end
Player Gets Hit:
local function playerHit() composer.gotoScene("level1-Try-Again") lives[livesCount].alpha = 0 livesCount = livesCount - 1 if(livesCount \< 1) then onGameOver() end end
May someone please help me in resolving this matter so I may move forward with my game. Thank you.
Sincerely,
Alex