timer - 在 Corona SDK 中循环调用计时器

标签 timer lua coronasdk

无限次调用我正在使用的计时器

function A()
    print("Hello")
    timer.performWithDelay(100, B, 1)
end

function B()
    timer.performWithDelay(500, A, 1)
end

timer.performWithDelay(100, A, 1)

因此,如果我想在特定的时间间隔内打印 hello,我可以使用这两个函数进行调整。 但我面临的问题是一段时间后计时器变慢并非常快地调用函数 A 。 如果我做得对的话,有人可以建议我吗?要解决计时器问题我该怎么办?

提前致谢。

最佳答案

如果您想无限次调用计时器,您可以使用:

timer.performWithDelay(100, functionName, -1)

timer.performWithDelay(100, functionName, 0)

就您而言,您需要在再次调用之前取消计时器。因此,请执行以下操作:

local timer_1,timer_2,timer_3
function A()
    print("Hello")
    if(timer_1)then timer.cancel(timer_1) end  -- cancelling 'timer_1' if exists
    if(timer_3)then timer.cancel(timer_3) end  -- cancelling 'timer_3' if exists
    timer_2 = timer.performWithDelay(100, B, 1) 
end

function B()
    if(timer_2)then timer.cancel(timer_2) end  -- cancelling 'timer_2' if exists
    timer_3 = timer.performWithDelay(500, A, 1)
end

timer_1 = timer.performWithDelay(100, A, 1) 

在这里你可以看到,我创建了计时器对象(timer_1、timer_2和timer_3),并在调用另一个/同一个计时器之前取消可能正在进行的计时器。

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

关于timer - 在 Corona SDK 中循环调用计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22033075/

相关文章:

c++ - qt按住鼠标按钮和定时器cpp

.net - 将表转换为字节数组

lua - 高 Aerospike 延迟

c++ - Linux、C++、Lua 5.3、CMake、未定义引用

javascript - 与定时器异步运行

android - 实时测量蓝牙信号强度 (RSSI)

Java实时固定时间间隔

php - Android(Corona sdk)触发的MYSQL PHP对行/列造成麻烦

string - 使用 Lua 从 URL 获取文件名

lua - corona sdk线速度慢?