Setting Up HighScore in Swift and Sprite Kit using NSuserdefaults

前端 未结 2 1935
闹比i
闹比i 2021-02-06 18:41

I am building a swift game and a need to set up a highscore , i have been trying to figure out how to do it for a while. So please can you tell me how to search this library to

2条回答
  •  梦如初夏
    2021-02-06 19:40

    var defaults=NSUserDefaults()
    var highscore=defaults.integerForKey("highscore")
    
    if(Score>highscore)
    {
        defaults.setInteger(Score, forKey: "highscore")
    }
    var highscoreshow=defaults.integerForKey("highscore")
    
    lblHighScore.text="\(highscoreshow)"
    println("hhScore reported: \(lblHighScore.text)")
    lblPlayScore.text="\(Score)"
    println("play reported: \(lblPlayScore.text)")
    

提交回复
热议问题