在 Windows Phone 7 和 XNA 4.0 中使用 XML 文件

发布于 2024-10-05 04:22:47 字数 208 浏览 0 评论 0原文

我正在为Windows Phone 7 上的XNA 4.0 开发一个基本的平铺引擎。我有一堆mapdata xml 文件,其中包含所有平铺位置、加电位置等。

我想知道使用这些的最佳方法是什么?我读过,如果我想将它们与内容一起使用,那么我必须更改 xml 文件的布局。

有什么方法可以将这些文件加载​​到项目中的设备上并从中读取数据吗?

非常感谢, 蚂蚁。

I'm working on a basic tiling engine for XNA 4.0 on Windows Phone 7. I have a bunch of mapdata xml files with all the tile positions, powerup positions etc.

I was wondering what the best way of using these? I've read that if I want to use them with the Content then I have to alter the layout of the xml files.

Is there any way to load these files on to the device within the project and read the data from them?

Many thanks,
ant.

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

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

发布评论

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

评论(1

山有枢 2024-10-12 04:22:47

我这样做的方法是使 XML 文件成为嵌入式资源,而不是内容,然后我可以在代码中访问它们:

Assembly app = Assembly.GetExecutingAssembly();
        XmlSerializer ser = new XmlSerializer(typeof(xmlType));
        string[] resources = app.GetManifestResourceNames();

        foreach (string resourceName in resources)
        {                                 
         xmlObject = (xmlType)ser.Deserialize(new StreamReader(app.GetManifestResourceStream(resourceName)));                    
        }

xmlType 是代表我的 XML 格式的类

The way I did it was make the XML file an embedded resource, not content, then I could access them in code:

Assembly app = Assembly.GetExecutingAssembly();
        XmlSerializer ser = new XmlSerializer(typeof(xmlType));
        string[] resources = app.GetManifestResourceNames();

        foreach (string resourceName in resources)
        {                                 
         xmlObject = (xmlType)ser.Deserialize(new StreamReader(app.GetManifestResourceStream(resourceName)));                    
        }

xmlType is a class that represents my XML Format

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