I have set a timer in my code below. How can I make the timer reset every time it reaches a given duration say, 7 seconds?
class SpriteGroup {
var sprites : [Sprite]
var isVisible : Bool
var startTime: TimeInterval = 0.0
var currentTime: TimeInterval = 0.0
init(sprites : [Sprite], isVisible: Bool, pos: CGPoint) {
self.sprites = sprites
...
startTime = Date.timeIntervalSinceReferenceDate
Timer.scheduledTimer(timeInterval: 1,
target: self,
selector: #selector(self.advanceTimer(timer:)),
userInfo: nil,
repeats: true)
}
func advanceTimer(timer: Timer)
{
currentTime = Date.timeIntervalSinceReferenceDate - startTime
}
I would probably do it like this instead
I've added a subclass of Clouds to show you how their Timer is affected by the update of the Scene, it just scrolls clouds across the scene at at an even pace regardless of device performance