CoronaSDK - 单击时从场景中删除计时器

CoronaSDK - Remove timer from scene on click

我有一个 newCircle,单击它会更改圆圈的颜色并启动一个计时器。我希望能够再次单击圆圈并将其更改回黑色并从场景中完全删除计时器。

delta = 0

local function tapListener( event )
    if (delta == 0) then
        c1:setFillColor(1,1,0)

        local timeLimit = 20
        timeLeft = display.newText(timeLimit, c1.x, c1.y, native.systemFontBold, 14)
        timeLeft:setTextColor(255,0,0)

        local function timerDown()
           timeLimit = timeLimit-1
           timeLeft.text = timeLimit
             if(timeLimit==0)then
                print("Time Out") -- or do your code for time out
             end
          end
        aTimer = timer.performWithDelay(1000,timerDown,timeLimit)            

        delta = delta + 1

    else 
        c1:setFillColor(0,0,0)

        delta = delta - 1


    end

答案:

else 
    c1:setFillColor(0,0,0)
    timer.cancel( aTimer )
    timeLeft.alpha = 0
    delta = delta - 1


end

timer.cancal( aTimer ) 停止计时器,timeLeft.aplha = 0 隐藏显示计时器的文本