2013-06-27 27 views
1

我正在制作一个在日冕游戏。我正在寻找一些东西在我的代码中停留5秒钟。我发现timer.perform延迟,但它不工作,我需要的东西,停止所有的代码5秒。有人可以帮我吗?需要类似等待或延迟在日冕sdk

我想在这个转换之后等待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}) 

回答

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}) 
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 -- 

保持编码............ :)

+0

'计时器。如果你想要函数被调用一次,performWithDelay(5000,yourFunction)'就足够了。第三个参数,即迭代次数是可选的。 – lomza