sprite Kit save highest score

前端 未结 2 1532
你的背包
你的背包 2021-01-15 21:56

I build a game using Sprite Kit(with swift xCode 6 beta 4) and I need to keep the highest score that the player reached(so just an one Int). I know there is a way to do it u

2条回答
  •  隐瞒了意图╮
    2021-01-15 22:20

    You can save the highest score in NSUserDefaults. It is used to persist small amount of data and really easy to use.You can save the highest score like

    // To save highest score
    var highestScore:Int = 20
    NSUserDefaults.standardUserDefaults().setObject(highestScore, forKey:"HighestScore")
    NSUserDefaults.standardUserDefaults().synchronize()
    
    // To get the saved score
    var savedScore: Int = NSUserDefaults.standardUserDefaults().objectForKey("HighestScore") as Int
    println(savedScore)
    

    NSUserDefaults is mainly used for persisting these kind of data like high-score of user.

提交回复
热议问题