【问题标题】:Corona SDK, Timer pause and resume does not work?Corona SDK,定时器暂停和恢复不起作用?
【发布时间】:2017-05-29 11:17:52
【问题描述】:

我的定时器暂停和恢复不起作用?它有一个逻辑错误,说 WARNING:timer.resume(timerID)ignored b/c is not paused。任何想法?我应该添加添加或删除侦听器以删除以停止计时器的转换吗?

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

【问题讨论】:

    标签: timer lua coronasdk


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      例子

      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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-06
        相关资源
        最近更新 更多