C# 和 XNA 中的游戏配置
读取和写入游戏配置的最简单方法是什么,例如:是否显示 fps 或播放声音等。
也许 xna 中有一些类可以用来做到这一点?
我真的不想在 XNA 游戏中使用默认的 C# XML 东西。
What is the simplest way to read and write game configurations like: whether to show fps or play sound, etc.
Maybe there are some class in xna that can be used to do that?
I don't really want to use default C# XML thingy for an XNA game.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想提出一个更简单的答案。我认为这些配置更改仅用于开发期间的测试,对吧?那么为什么不简单地为您的设置创建一个静态类:
这样,您就不必编写任何代码来从磁盘读取值。您所要做的就是类似于
if (Debugging.ShowFPS)
之类的操作。除了设置静态字段 (Debugging.ShowFPS = false;
) 之外,您也不必编写任何代码来在运行时更改值。想想看,如果您将值存储在 XML 文件中,您的工作流程将是:
工作流程完全相同,但还有一个额外的好处:不必编写任何代码来处理读取和写入。它也可以在所有支持的平台上完全不做任何更改地工作。如果您想 100% 确保在发布前不会忘记更改设置,您可以使用一个简单的 ifdef 以及正确的生产值:
有时,最好的答案是最简单的;-)
I'd like to propose a much simpler answer. I assume these configuration changes are only for testing during development right? Then why not simply have a static class with your settings:
This way, you don't have to write any code for reading the values from disk. All you have to do is something like
if (Debugging.ShowFPS)
. You also don't have to write any code to change the values at runtime other than setting a static field (Debugging.ShowFPS = false;
).Think about it, if you store your values in, say, an XML file, your work flow will be:
the workflow is exactly the same, with the added benefit that you don't have to write any code to deal with reading and writing. It also works with absolutely no changes on all supported platforms. And if you want to be 100% sure that you don't forget to change a setting before releasing, you can use a simple ifdef with the correct values for production:
Sometimes, the best answer is the simplest ;-)
既然您提到您可能想要移植到 xbox,我建议使用名为 EasyStorage 的库。这是很多人在进行简单的阅读/写作时使用的方法。
它允许玩家选择他们的存储设备(如果存在多个存储设备),以及玩家在尝试保存之前删除存储设备等。它会给你一个用于保存/加载的流,所以大多数您的实际保存/加载代码将是相同的。
Since you've mentioned that you might want to port to the xbox, i'd recommend using a library called EasyStorage. It's what a lot of people use when doing simple reading/writing.
It deals with allowing the player to choose their storage device (if more than one exist) and with things like the player removing the storage device before trying to save etc. It'll give you a Stream to save/load from, so most of your actual saving/loading code will be the same.