I have created a simple timer in Xcode for a game (SpriteKit):
The variables timer, seconds and score are initialized in the class.
func scoreTimer() {
timer = Timer.scheduledTimer(timeInterval: 0.05, target: self, selector: #selector(countUp), userInfo: nil, repeats: true)
}
@objc func countUp() {
seconds += 0.05
seconds = (seconds * 100).rounded() / 100
score = score + 0.015
updateScore()
}
func updateScore() {
scoreLabel.text = "\(score)"
}
The timer is started in didMove() when the GameScene has been loaded.
I try to call countUp() every 0.5 seconds. In this function the variable seconds is increased and rounded plus the score variable is increased. From there I would like to call the updateScore function to update the scoreLabel.text - but this doesn't work. The function is called, but the scoreLabel is not updated although when I try to print the score variable, it shows that it is increased constantly.
How can I achieve this and what's is wrong here?