# Implementing score relative to total game time

How would one create score dependent on total time in game? I would like the score to count by 1000+ each second the game is running for. Later I am going to add some coins which will give my total score +1000 also.

How would one create this functionality? This is all I have right now:

  let scoreDisplay = UILabel()
scoreDisplay.text = "Score: \(self.score)"
scoreDisplay.textColor = UIColor.red
scoreDisplay.frame = CGRect(x: mainWidth / 2 - 200, y: mainHeight - 400, width: 247, height: 100)

let delay = SKAction.wait(forDuration: 0.25)
let incrementScore = SKAction.run ({
self.score = self.score + 1
self.scoreDisplay.text = "\(self.score)"
})


I'm pretty new to Swift, so sorry for my basic question!

• First you need to have a timer variable that only starts counting when the game has started. some programming languages have build-in timers, but those usually already starts when the application is running (depends if you've a main menu, or reset option). once you've that timer variable, you can use that to count up the score. – Steven Jan 11 '19 at 14:01
• @Steven that looks to me like the start of a good answer! Care to flesh it out as an answer post? – DMGregory Jan 11 '19 at 14:34
• @Steven thanks for the reply, if you could please give me some code relating to mine, that would seriously help me a lot! Thank you :) – JimmyK1 Jan 11 '19 at 14:54

But you can set a timer variable on your own, similair as how you've defined your scoreDisplay, then add +1 everytime the code gets past the timer variable. problem is however that it calculates in code-ticks, instead of seconds, and it may not be accurate in case of a frame drop.