Timer with random seconds ¿How to update the random seconds?
Posted
by
benLIVE
on Stack Overflow
See other posts from Stack Overflow
or by benLIVE
Published on 2014-06-02T03:20:55Z
Indexed on
2014/06/02
3:25 UTC
Read the original article
Hit count: 411
I have a timer "tmr_sendCesta
" which must be called each x seconds between 1 and 3 seconds. The problem is the timer "tmr_sendCesta
" is called only one time, and the random seconds is never updated. I need to call the function "createCesta
" each x seconds randomly.
Any idea how to do it?
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), randomCesta, 0)
end
© Stack Overflow or respective owner