In my game, meteors fall from the sky. The spawnMeteorite function is called upon at the beginning of the game and calls on itself after a delay has been satisfied, where the new delay between meteorites is slightly less than before.
func spawnMeteorite(timeInterval:Double) {
delay(timeInterval) {
self.spawnMeteorite(timeInterval: timeInterval*0.9)
}
// Create meteorites
}
func delay(_ delay:Double, closure:@escaping ()->()) {
let when = DispatchTime.now() + delay
DispatchQueue.main.asyncAfter(deadline: when, execute: closure)
}
I have successfully been able to pause all the animations in my GameScene with self.view?.isPaused = false. However, the meteors continue to spawn, because the code itself still runs.
Is there any way to pause all ongoing delays in my program, so that if the game was paused mid-way through a 3-second delay, when resumed, the delay would continue for 1.5 more seconds? This would mean the rate of meteorite spawns would not be interrupted. Thanks.