Hey guys. I’m making a game. You play the game, as time passes your score builds, and when you hit something (lose the game) you go to the restart screen. What I want to do is be able to show the score on the restart screen, but I’m have some trouble because I can’t get the score to stop when you lose the game (when your jet, in this case, collides with something).
My code is something like this:
scoreTxt = display.newText( "Score: 0", .5,.5, "Helvetica", 20) scoreTxt:setFillColor(.5,0,.5) scoreTxt.AnchorX = 0 scoreTxt.x = display.screenOriginX + 450 scoreTxt.y = display.screenOriginY + 20 screenGroup:insert(scoreTxt) score = 0 function updateScore() score = score + 1 scoreTxt.text = score end timer.performWithDelay(1, updateScore, -1) function onCollision(event) if event.phase == "began" then storyboard.gotoScene("restart", "fade", 400) end end Runtime:addEventListener("collision", onCollision)
(I only picked the relevant pieces of code to copy and paste. And I also know the “Score:0” doesn’t actually do anything, but all I care about is having the numbers on the screen.)
How can I stop updateScore from continuing when something collides?
Thanks in advance!
-Tariq