【发布时间】:2014-06-02 03:20:55
【问题描述】:
我有一个计时器“tmr_sendCesta”,必须在 1 到 3 秒之间每隔 x 秒调用一次。问题是定时器“tmr_sendCesta”只被调用一次,随机秒数永远不会更新。我需要每 x 秒随机调用一次函数“createCesta”。
知道怎么做吗?
function createCesta()
cesta = display.newImageRect("cesta.png", 100, 55)
cesta.x = -110
cesta.y = screenH - 110
cesta.name = "cesta"
physics.addBody( cesta, physicsData:get("cestaSmall"))
grupoCesta:insert(cesta)
transition.to(cesta, {time = 4000, x = screenW + 110})
end
function scene:enterScene( event )
local group = self.view
physics.start()
Runtime:addEventListener("touch", touchScreen)
Runtime:addEventListener( "collision", onCollision )
tmr_sendCesta = timer.performWithDelay(math.random(1000, 3000), createCesta, 0)
end
【问题讨论】:
标签: random timer lua coronasdk 2d-games