Ryan Allen
Ryan Allen

Reputation: 943

How do I display my timer in my SKLabelNode?

The score of my game depends on the time you have stayed alive. Although my output log displays the timer counting up, the SKLabelNode stays at 0 on the screen.

    self.scoreText.text = "0"
    self.scoreText.fontSize = 60
    self.scoreText.position = CGPoint(x: CGRectGetMidX(self.frame), y: 500)
    self.scoreText.text = String(self.score)
    self.addChild(self.scoreText)
    timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("scoreIncrease") , userInfo: nil, repeats: true)
}
// end didMoveToView
func scoreIncrease (){
    score++
    println(score)
}

Why does scoreText remain at 0 on the game scene? Thanks in advance for the help and I can respond tomorrow with any other info you may need to help out!

Upvotes: 0

Views: 70

Answers (1)

Brennan Adler
Brennan Adler

Reputation: 915

Although you are continuously updating the value of score on the timer, you aren't updating the text on your LabelNode. All you have to do is update the text within your func scoreIncrease()

func scoreIncrease (){
score++
self.scoreText.text = String(self.score)
println(score)
}

Upvotes: 1

Related Questions