如果我想要根据得分的增加取消计时器,我需要写什么?(Corona)

我正在尝试在玩家选择正确字符时取消计时器。我得出结论,这种情况下取消计时器的两种可能方式是基于分数增加或基于addEventListener的初始化。我尝试了一些可能的选项,但它们都不起作用。有什么想法吗?如何使条件成立,以便计时器基于事件取消?以下是我到目前为止的代码:

function timeClock(event)
如果事件时间大于2000,则
storyboard.gotoScene(“restartEasy”)
randomImage.alpha = 0
否则
timer.cancel(event.source)
结束
end

function endGame(event)
如果imageFile ==“redbox.png”那么
timer.performWithDelay(2000,timeClock)
randomImage.alpha = 0
mydata.score = mydata.score + 1
scoreText.text = mydata.score
button1.x = math.random(55,300)
button1.y = math.random(55,300)
button2.x = math.random(55,300)
button2.y = math.random(55,300)
imageFile = imageFiles [math.random(2)]
randomImage = display.newImage(imageFile,centerX,screenTop + 20)
storyboard.gotoScene(“restartEasy”)
randomImage.alpha = 0

结束
end

function endGame2(event)
如果imageFile ==“bluebox.png”那么
timer.performWithDelay(2000,timeClock)
randomImage.alpha = 0
mydata.score = mydata.score + 1
scoreText.text = mydata.score
button1.x = math.random(55,300)
button1.y = math.random(55,300)
button2.x = math.random(55,300)
button2.y = math.random(55,300)
imageFile = imageFiles [math.random(2)]
randomImage = display.newImage(imageFile,centerX,screenTop + 20)
否则
storyboard.gotoScene(“restartEasy”)
randomImage.alpha = 0

结束
end

button1:addEventListener(“touch”,endGame)
button2:addEventListener(“touch”,endGame2)

结束
点赞
用户825481
用户825481

将计时器命名为公共变量,比如

timer1 = timer.performWithDelay(2000, timeClock)

然后在你的函数中使用以下代码取消计时器

timer.cancel(timer1)
2015-04-14 22:08:39