[英]How do I properly reference Content in Visual Studio 2010 with XNA?
I'm making a C# game using Visual C# Studio 2010 Express with Microsoft's XNA. 我正在使用带有Microsoft XNA的Visual C#Studio 2010 Express制作C#游戏。
At the moment I'm trying to load content into the game but I'm having trouble with the relative Content path. 目前,我正在尝试将内容加载到游戏中,但是相对的Content路径存在问题。 My current code looks like this:
我当前的代码如下所示:
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");
}
The Content.RootDirectory
is currently set to "Content". Content.RootDirectory
当前设置为“内容”。
How do I construct the paths to the images so that they will load? 如何构造图像的路径,以便它们加载? At the moment I get a
ContentLoadException: file not found
, so clearly my relative path is wrong. 目前,我得到了
ContentLoadException: file not found
,因此很明显我的相对路径是错误的。 Where does the path start from? 路径从哪里开始?
Remove file extensions: 删除文件扩展名:
planetBackground = Content.Load<Texture2D>("spacebackground");
XNA transforms all files into .XNB files, so there's no need to specify extensions (unless your files have multiple dots in file names). XNA将所有文件转换为.XNB文件,因此无需指定扩展名(除非文件名中包含多个点)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.