sprite Kit 保存最高分 [英] sprite Kit save highest score

查看:25
本文介绍了sprite Kit 保存最高分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Sprite Kit(使用 swift xCode 6 beta 4)构建了一个游戏,我需要保持玩家达到的最高分(所以只有一个 Int).我知道有一种使用 NSCoding 的方法,我用谷歌搜索了它,发现只有我不能使用的 Objective-C 教程/指南,因为我根本不知道 Objective-c,也许有更好的方法来了在 xCode 的最新版本中.任何帮助将不胜感激!

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 using NSCoding, I googled it and found only Objective-C tutorials/guides which I can't use because I don't know objective-c at all, and maybe there are better ways that came in late versions of xCode. Any help will be appreciated!

推荐答案

最高分可以保存在NSUserDefaults.它用于持久化少量数据,非常易于使用.您可以保存最高分,例如

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主要用于持久化用户高分等这类数据.

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

这篇关于sprite Kit 保存最高分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆