我正在使用 Visual C# Studio 2010 Express 和 Microsoft XNA 制作 C# 游戏。
目前我正在尝试将内容加载到游戏中,但我在相对内容路径方面遇到了问题。我当前的代码如下所示:
private Texture2D planetBackground;
private Texture2D groundFacility;
private Texture2D hoverShip;
private Texture2D attackShip;
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
planetBackground = Content.Load<Texture2D>("spacebackground.png");
groundFacility = Content.Load<Texture2D>("planetstation.png");
hoverShip = Content.Load<Texture2D>("ship2.png");
attackShip = Content.Load<Texture2D>("ship1.png");
}
Content.RootDirectory
当前设置为“Content”。
如何构建图像的路径以便加载它们?目前我收到一个 ContentLoadException: file not found
,所以显然我的相对路径是错误的。路径从哪里开始?
最佳答案
删除文件扩展名:
planetBackground = Content.Load<Texture2D>("spacebackground");
XNA 将所有文件转换为 .XNB 文件,因此无需指定扩展名(除非您的文件的文件名中有多个点)。
关于c# - 如何使用 XNA 正确引用 Visual Studio 2010 中的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26390064/