我应该在哪里保存 cocos2d Iphone 游戏的金币/经验值属性?
我想保存我的金币和经验属性,以便在应用程序启动时可以检索它们。
我不知道是否应该使用 .plists 还是 NSUserdefaults。有什么区别?我可以在代码之外的某个地方手动编辑 NSUserdefaults 就像我可以使用 plist 那样吗?问题是,我不希望用户因任何原因失去所有的金币/经验值。
Gold 和 exp 都是整数值。您认为 NSUserdefaults 是正确的选择吗?
I'd like to save my gold and experience attributes so that they can be retrieved whenever the app launches.
I don't know whether I should use .plists or NSUserdefaults. What's the difference? Can I somewhere manually edit the NSUserdefaults outside of the code like I can do it with plists? The problem is, I don't want the user to loose all his gold/exp for any reason.
Gold and exp are both integer values. Do you think NSUserdefaults would be the right choice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NSUserDefaults 在升级期间保留。它很容易使用(一行代码即可保存/恢复设置)。
任何可以篡改它们的人都无法使用它们——除非他们越狱了手机,那么我想无论你使用什么方法,人们都可以得到它们。
如果您对这种情况完全偏执,您可以在保存/恢复期间加密/解密数据,但这可能有点过头了。
NSUserDefaults are retained during an upgrade. It is easy to use to (a one-liner to save/restore settings).
They are not available to anyone who could tamper with them - unless they jailbroke the phone, then I suppose people could get at them no matter what method you use.
If you are totally paranoid about that scenario, you could encrypt/decrypt the data during save/restore, but that's probably overkill.