在 iOS 上保存用户游戏分数

发布于 2024-10-22 04:42:17 字数 194 浏览 5 评论 0原文

我正在开发一款 iOS 游戏,我有两个问题。首先,我将关卡信息(分数、背景图像等)维护到 plist 文件中。第一次启动应用程序时,我将 plist 文件从资源目录复制到文档目录(我需要将用户最好成绩写入其中)。退出维护这些信息的最佳方式是什么?其次,如果我对应用程序进行更新,例如添加新级别,如何在不丢失当前用户分数的情况下添加更新新信息?

感谢您的阅读。

I am developing an iOS game and I have two questions. First, I am maintaining the levels information (scores, background image, etc) into a plist file. The first time that the app is launched, I copy the plist file from the resources directory to the documents directory (I need to write the user best scores into it). Exits a best way to maintaing this information? Second, if I make an update of the app, adding new levels par example, how can I add the update new information without losing the current user scores?

Thanks for reading.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

方觉久 2024-10-29 04:42:17
  1. 属性列表似乎是跟踪高分等的好方法。如果您已经做到了这一点,请坚持下去,直到您有充分的理由进行更改。

  2. 当用户更新到应用程序的新版本时,您的数据文件(实际上是 Documents 目录的全部内容)将被保留。

  1. A property list seems as good a way to keep track of high scores and such as any other. If you've already got that working, stick with it until you have a good reason to change.

  2. Your data file (indeed, the entire contents of the Documents directory) will be preserved when the user updates to a new version of the app.

栖竹 2024-10-29 04:42:17

正如 Caleb 所说,pList 文件可能适合保存高分。

我想补充一些关于#2 的内容。为了简单起见,只要您提前计划更新,您就可以始终重复使用相同的保存文件。这比尝试为不同版本处理不同的 plist 文件要容易得多。

当您创建游戏保存 plist 文件时,请确保包含保存游戏格式版本号字段。这样,对于未来的版本,您可以打开保存文件,读取版本号,并进行任何必要的调整以将其升级到当前版本。当玩家基本上可以跳过更新、下载版本 1 和 3 但跳过 2 时,这非常方便。

AS Caleb said, a pList file is probably fine for saving high scores.

I'd like to add a bit about #2. You can just always re-use the same save file for simplicity, as long as you plan ahead for updates. This is a lot easier than trying to juggle different plist files for different versions.

When you create your game save plist file, just be sure to include a field for a save game format version number. That way, for future releases, you can open the save file, read the version number, and make any necessary adjustments to bring it up to the current version. This is extremely handy when players can essentially skip updates, downloading version 1 and 3 but skipping 2.

許願樹丅啲祈禱 2024-10-29 04:42:17

我同意迦勒的观点。最好有一些源代码来帮助您。

我创建了此示例代码,它具有本地和全球支持。

I agree with Caleb. It's best to have a little source code to help you.

I created this sample code that has both local and global support.

人疚 2024-10-29 04:42:17

您可能想看看 NSUserDefaults 类,提供存储应用数据的基本管理功能。对于更高级的数据存储,CoreData 是推荐的方式。

You might want to have a look at the NSUserDefaults class which provides basic management capabilities for storing app data. For more advanced data storage, CoreData is the recommended way to go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文