Using SpriteKit and Timers in Swift, I am trying to create a feature that will pause the game, and resume with the correct time. I found an awesome source "Pausing" the Game in Swift that showed a system allowing just that. In my code I have the function pauseGame that should allow me to get the current time that the timers were invalidated at
func pauseGame(){
enemyTimer.invalidate()
enemyTimer2.invalidate()
changeSpeed.invalidate()
rubyTimer.invalidate()
// 0.3 is the original delay time when the timers were created
let calendar = Calendar.current
let timeCaptured = calendar.date(byAdding: .nanosecond, value: Int(Int64(0.3 * Double(NSEC_PER_SEC))), to: Date())!
let elapsedTime = timeCaptured.timeIntervalSince(Date)
let remainingDelay = 0.3 - elapsedTime
}
All I have to do is create new timers with the value of remainingDelay, however I get an error on
let elapsedTime = timeCaptured.timeIntervalSince(Date)
saying "Cannot convert value of type '(Date).Type' to expected argument type 'Date'"
Any ideas? Thanks for looking into it.