I'm making a game with SpriteKit and it saves the player's high score. When the game ends it transitions into a different scene (endScene). I can't figure out how to display the high score in the endScene. Code I have for my high score:
func updateHighScore(){
//save current points label value
let pointsLabel = childNodeWithName("pointsLabel") as! DDPointsLabel
let highScoreLabel = childNodeWithName("highScoreLabel") as! DDPointsLabel
if highScoreLabel.number < pointsLabel.number {
highScoreLabel.setTo(pointsLabel.number)
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setInteger(highScoreLabel.number, forKey: "highscore")
}
}
func loadHighScore(){
let defaults = NSUserDefaults.standardUserDefaults()
let highScoreLabel = childNodeWithName("highScoreLabel") as! DDPointsLabel
highScoreLabel.setTo(defaults.integerForKey("highscore"))
}
To load the highscore, you are going to need a int to hold the highscore, I'm not sure what you are trying to do with the highScoreLabel, but to load it you would do
var highScore = defaults.integerForKey("highScore")
and for your label you can dohighScoreLabel.text = "Score \(highScore)"