Corona SDK,定时器暂停和恢复不起作用?

时间:2017-01-14 00:38:01

标签: timer lua corona

我的计时器暂停和恢复不起作用?它有一个逻辑错误,表示警告:timer.resume(timerID)被忽略b / c没有暂停。任何的想法?我应该添加添加或删除侦听器来删除以停止计时器的转换吗?

local timerEnabled = true --  Stops or allows our countdown timer       
local touchEnabled = false      

local delay_timer               
local timer_trans   -- transition of my timerbar           

local timer_rect      --display object          
local timer_bar        -- display object       

function pauseGame(  )
    if (timerEnabled==false) then
            timer.pause(timer_bar)
            answer_rect:removeEventListener( "touch", buttonTouched )

    elseif (timerEnabled==true) then
            timer.resume(timer_bar)    
            answer_rect:addEventListener( "touch", buttonTouched )

    end
end


local pauseButtonPress = function( event )
    pauseGame()
end

        timer_rect = display.newRect(uiGroup, _W*0.5, question_rect.y+question_rect.height, _W, 50 )
        timer_rect.anchorY = 0
        timer_rect:setFillColor(0,0.3,0.7)

    if timerEnabled == true then 
        timer_bar = display.newRect(uiGroup, 0, timer_rect.y+timer_rect.height-20, _W, 35)
        timer_bar.anchorX = 0 
        timer_bar:setFillColor(0.8,1,1)
    end

        pauseButton= widget.newButton{       
        defaultFile = "images1/Buttons/Pause.png",
        overFile= "images1/Buttons/Resume.png",
        onRelease = pauseButtonPress,
    }
        pauseButton.x = 100
        pauseButton.y = 90
        pauseButton.xScale = .6
        pauseButton.yScale = .6

2 个答案:

答案 0 :(得分:0)

timer.pause()和timer.resume()应该接收一个timerID作为param,而不是对象。

答案 1 :(得分:0)

示例

local function listener( event )
    print( "listener called" )
end

timer1 = timer.performWithDelay( 2000, listener )  -- wait 2 seconds

-- sometime later...
local result = timer.pause( timer1 )
print( "Time remaining is " .. result )

您可以在timer.pause()找到有关timer.resume()documentation的更多信息。