I'm developing a game and I want to create a pause menu. Here is my code:
self.view?.paused = true
but NSTimer.scheduledTimerWithTimeInterval still running..
for var i=0; i < rocketCount; i++ {
var a:NSTimeInterval = 1
ii += a
delaysShow = 2.0 + ((stimulus + interStimulus) * ii)
var time3 = NSTimer.scheduledTimerWithTimeInterval(delaysShow!, target: self, selector: Selector("showRocket:"), userInfo: rocketid[i] , repeats: false)
}
I want time3 to pause the timer when player click pause menu and continue run the timer when player come back to the game, but how can I pause NSTimer.scheduledTimerWithTimeInterval? help me please.
Pause timer : timer.invalidate()
and
Resume timer : recreate timer. it's work fine.
To Start:
To Resume:
To Pause:
This worked for me. The trick is that do not look for something like
"timer.resume"
or"timer.validate"
. Just use "the same code for starting a timer" to resume it after the pause.