I need help in setting up a collision on an object which interacts with the timer countdown by increasing the current time.
As I’m still grasping coding I am stuck in trying to get this to work. What I want to happen is the player collides into the star and the time increases by 5 secs.
Here is my set up.
Timer
function timerDown() timeLimit = timeLimit-1 timeLeft.text = timeLimit if(timeLimit==0 and tonumber(collectedN.text) \>= tonumber(requiredN.text)) then alert('win') elseif(timeLimit==0 and tonumber(collectedN.text) \< tonumber(requiredN.text)) then alert('lose') end end timer.performWithDelay(1000,timerDown,timeLimit)
Star collision
function ship:collision(event) if (event.other.name == 'star') then timeLeft.text = tostring(tonumber(timeLeft.text) + 5) timeLeft.text = timeLimit --removes star event.other:removeSelf(star) scoreAnim = display.newText('+10', ship.x, ship.y-10, native.systemFontBold, 16) transition.to(scoreAnim, {time = 1000, y = scoreAnim.y - 30, alpha = 0, onComplete = function() display.remove(scoreAnim) scoreAnim = nil end}) scoreAnim:setTextColor(0,255,12) Runtime:removeEventListener("enterFrame", star) --increases score collectedN.text = tostring(tonumber(collectedN.text) + 1) print('star successful')
