hey guys,
I’m having a problem with timers. Sometimes when a timer is paused and resumed the createShot() function delay a bit to resume.
This is a bit about my code :
[lua] createShot = function()
local bullet = display.newImage(bullets, “bullet.png”)
bullet.x = player.x
bullet.y = player.y - (player.height * .5) - 8
bullet.myName = “bullet”
physics.addBody(bullet, {filter = bullet_CollisionFilter} )
bullet.collision = collisionEvent
bullet:addEventListener(“collision”, bullet)
audio.play(shotSound)
end
createBack = function(imageName)
local imageBack = display.newImage(backs, imageName…".png")
imageBack.x = createRandom(imageBack.width, w - imageBack.width)
imageBack.y = -imageBack.height
imageBack.myName = imageName
physics.addBody(imageBack, “dynamic”, {filter = back_CollisionFilter})
end
timers[1] = timer.performWithDelay(150, createShot, 0)
timers[6] = timer.performWithDelay(1000,
function()
createBack(“starSmall”)
end, 0)
timers[7] = timer.performWithDelay(3000,
function()
createBack(“starBig”)
end, 0)
timers[8] = timer.performWithDelay(3500,
function()
createBack(“speedLine”)
end, 0)
timersFunction = function(timerType)
if timerType == “pause” then
timer.pause(timers[1])
timer.pause(timers[6])
timer.pause(timers[7])
timer.pause(timers[8])
elseif timerType == “resume” then
timer.resume(timers[1])
timer.resume(timers[6])
timer.resume(timers[7])
timer.resume(timers[8])
elseif timerType == “cancel” then
for j=1, #timers do
if timers[j] ~= nil then
timer.cancel(timers[j])
timers[j] = nil
end
end
timers = nil
end
end
pauseGame = function(e)
if e.phase == “began” then
if pause then
timersFunction(“pause”)
physics.pause()
pause = false
else
timersFunction(“resume”)
physics.start()
pause = true
end
end
end[/lua]
Still there is a function to move the bullet and the background but i think it is enough to understand my problem.
someone can help me ?
thanks. [import]uid: 95474 topic_id: 33176 reply_id: 333176[/import]