在电晕sdk中需要等待或延迟的东西

时间:2013-06-27 17:55:41

标签: timer lua transition corona

我在日冕做游戏。我正在寻找能够在我的代码中停留5秒钟的东西。我发现timer.perform有延迟,但是它不起作用,我需要停止所有代码5秒的东西。有人可以帮我吗?

我希望在此过渡后等待5秒并继续使用代码。

transition.to(block[old], {time=tranTime, x=block[new].x, y=block[new].y})
transition.to(block[new], {time=tranTime, x=block[old].x, y=block[old].y})

2 个答案:

答案 0 :(得分:2)

local function yourFunction()
  print("This will get called 5seconds after block[old] transition...")
end

local function transitionFinished()
  print("Transition of block[old] is completed...")
  timer.performWithDelay(5000,yourFunction,1) --[[ If you want, you can use this 
                                                   line to call 'yourFunction' 
                                                   after desired time(here 5seconds) 
                                              --]]
end

transition.to(block[old], {time=tranTime, x=block[new].x, y=block[new].y, onComplete=transitionFinished})
transition.to(block[new], {time=tranTime, x=block[old].x, y=block[old].y})

否则,如果你想暂停所有过渡,那么有许多自定义类,你可以使用像DevfaR所说的那样。

或者如果您想在延迟后执行转换,您还可以使用:

transition.to(block[old], {delay=1000,time=tranTime, x=block[new].x, y=block[new].y}) 
-- this will get called after a delay of 1000ms --

继续编码............:)

答案 1 :(得分:0)

无法在一段时间内停止代码,但您可以做的是在转换中使用onComplete事件。例如:

local function1 = function()
    print("This will show after the transition finishes.")
end

transition.to(block[old], {time=tranTime, x=block[new].x, y=block[new].y, onComplete=function1})
transition.to(block[new], {time=tranTime, x=block[old].x, y=block[old].y})
相关问题