0
votes

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!

1
If the answer provided solved your question you should consider marking it as correct. - ABakerSmith
Alright, sorry I'm new but thanks for the tip. Is it fixed now? - Ryan Allen
Yeah, I'm sure @Brennan Adler will appreciate it :) I just thought I should mention it because you commented that it solved your problem. - ABakerSmith

1 Answers

1
votes

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)
}