【发布时间】:2014-02-19 18:12:51
【问题描述】:
我目前正在尝试将我正在开发的游戏从 XNA 移植到 Monogame,但我在让内容管道合作时遇到了一些麻烦。我的游戏使用许多 XML 文件作为 XNB 资源来表示游戏中的对象,这些文件是我按照说明 here 创建的。但是,尝试将其逐字逐句移动到 Monogame 中会产生以下错误:
MonoGame.Framework.dll 中出现“Microsoft.Xna.Framework.Content.ContentLoadException”类型的未处理异常
附加信息:无法将 Parts\Window.xnb 资源加载为非内容文件!
这是我用来定义 XML 文件内容的类:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace FileTypes
{
public class PartFile
{
public struct State
{
public Rectangle[] frames;
public int[] collision;
}
public Vector2 size;
public string image;
public string defaultState = "default";
public bool fillBG;
public int ticksPerFrame;
public Dictionary<string, State> states;
public string[] modules;
}
}
这是项目中的 XML 文件之一:
<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
<Asset Type="FileTypes.PartFile">
<size>2 3</size>
<image>Computer</image>
<defaultState>default</defaultState>
<fillBG>false</fillBG>
<ticksPerFrame>7</ticksPerFrame>
<states>
<Item>
<Key>default</Key>
<Value>
<frames>
0 0 40 60
40 0 40 60
</frames>
<collision>
0 0
0 0
0 0
</collision>
</Value>
</Item>
<Item>
<Key>active</Key>
<Value>
<frames>
80 0 40 60
120 0 40 60
</frames>
<collision>
0 0
0 0
0 0
</collision>
</Value>
</Item>
</states>
<modules>
<Item>testModule</Item>
</modules>
</Asset>
</XnaContent>
最后是我用来加载文件的代码示例:
FileTypes.PartFile srcPart = content.Load<FileTypes.PartFile>("Parts\\" + name);
有人知道我需要做什么才能让我的代码在 Monogame 中运行吗?我已经在互联网上寻找了一段时间,但到目前为止,我还没有找到解决我的问题的方法。或者,如果我一直在处理整个系统错误,并且有一种更简单的方法来处理我想做的事情,我很想听听。
提前致谢!
【问题讨论】: