我开始学习“一些”XNA,并且正如预期的那样,我很早就遇到了障碍。
- 我创建了一个 WP7 XNA 游戏解决方案
- 我已删除默认内容项目
- 我添加了自己的内容项目“Sprites”
- 我已将 3x *.png 文件添加到“Sprites”项目(MyImage1.png、MyImage2.png、MyImage3.png)
- 我添加了一个内容引用,将“Sprites”引用到主游戏项目
/**/
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
logoTexture = Content.Load<Texture2D>("Sprites/MyImage1");
// TODO: use this.Content to load your game content here
}
在尝试加载我的 *.png 时,我收到一个 ContentLoadException,提示“未找到”
- 我确实检查了输出目录,存在包含 *.xnb 文件的“Sprites”子文件夹
- 我确实检查了图像的属性,所有图像都标记为Texture2D,并将内容导入器和处理器设置为默认 XNA 值
我很确定我犯了一个常见的n00b'ish错误,但我没有看到它,所以我很感激一些指导。
问题已修复
Content.RootDirectory = "Content"; // The cause of the problem
问候
最佳答案
为什么要删除内容项目?
我的猜测是您需要设置 RootDirectory
Content.RootDirectory = "Content";
顺便说一句,哪个创建了 ContentManager 对象。
关于c# - XNA 内容加载异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5773095/