Hello,
I have many timers running in my game and I am trying to make the pause button function properly. Basically, when I go to pause, everything works correctly and pauses up. When I resume, things start to act strangely. For example, after resuming the timers, sometimes display objects end up moving extremely fast and sometimes all timers in the level will randomly freeze up and then begin again after a period of time.
Below is some code to pause and resume my timers. This probably isn’t the nicest code, but I wanted to be sure to get the “performWithDelay” in there when going through all of my existing timers. Also, when the pause button is hit, gameIsActive == false.
Are there any suggestions or ideas for workarounds?
local result
local h = 1
function pauseAllTimers()
if (h <= 25) then
if (timerIndex[h] ~=nil) then
result = timer.pause(timerIndex[h])
local timerToString = tostring(timerIndex[h])
print ("timer paused: " … timerToString )
print( "Time remaining is " … result )
end
h = h + 1
else
h = 1
print("Game Status: ", gameIsActive)
return
end
timer.performWithDelay(1, pauseAllTimers)
end
local z = 1
function resumeAllTimers()
if (z <= 25) then
if (timerIndex[z] ~=nil) then
result = timer.resume(timerIndex[z])
local timerToString = tostring(timerIndex[z])
print ("timer resumed: " … timerToString )
print( "Time remaining is " … result )
end
z = z + 1
else
z = 1
print("Game Status: ", gameIsActive)
return
end
timer.performWithDelay(1, resumeAllTimers)
end
function gameStart()
pauseListener(“add”)
gameListeners(“add”)
if (gameIsActive == true) then
updateBackgrounds()
timerIndex[1] = timer.performWithDelay(5000, updateGate, 1)
timerIndex[2] = timer.performWithDelay(10000, mouseRun, 1)
timerIndex[5] = timer.performWithDelay(10000, updateGate, 1)
timerIndex[3] = timer.performWithDelay(15000, ufoFlight, 1)
timerIndex[4] = timer.performWithDelay(30000, updateJet, 1)
timerIndex[6] = timer.performWithDelay(35000, ufoFlight, 1)
timerIndex[7] = timer.performWithDelay(45000, mouseRun, 1)
timerIndex[8] = timer.performWithDelay(50000, updateJet, 1)
timerIndex[9] = timer.performWithDelay(60000, ufoFlight, 1)
end
end
gameStart()