Ok…I have been trying to solve this problem for the past 3 days now and frankly speaking am about to loose my mind . I have read almost all blogs, tutorial and forum dealing with how to set up a health/lives system and still can get to a solution myself.
The problem seems to be the collision listener function. Whenever I try to add or deduct a life during a collision (“player and enemy” or “player and power-up”) it does the calculations twice. Thus always collision always fires twice.
Please how do i get around deducting and adding number variables within a collision event. Has anyone solved this issue and how. I tried the timer.performWithdelay as suggested in some tutorials but still the same.
local function onCollision( self, event )
if ( event.phase == “began” ) then
if ( event.target and event.other.objType == “enemy1” ) then
timer.performWithDelay(1000,
function()
lives = lives - 1
print(lives)
end, 1 )
end
end
end
–associate colllision handler function with character
player.collision = onCollision
player:addEventListener(“collision”, player)