简体   繁体   English

如何在带有XNA的Visual Studio 2010中正确引用内容?

[英]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.

相关问题 如何在Visual Studio Web 2010 Express中将XNA内容管道添加到Silverlight 5? - How to add XNA Content Pipeline to Silverlight 5 in Visual Studio Web 2010 Express? 如何在Visual Studio 2010中使用C#XNA While循环? - How do you use a C# XNA While Loop with Visual Studio 2010? 如何在Visual Studio 2010中添加对外部配置文件的引用? - How do I add a reference to an external configuration file to Visual Studio 2010? 如何使用C#和Visual Studio 2010在多个层之间共享服务引用类型 - How do I share Service Reference Types Across Multiple Tiers using C# and Visual Studio 2010 我可以在没有XNA Game Studio的情况下在Visual Studio 2010中使用XNA 4.0程序集吗? - Can I use XNA 4.0 assemblies inside Visual Studio 2010 without XNA Game Studio? 如何在Visual Studio 2010中引用辅助项目 - How to reference a secondary project in Visual Studio 2010 如何在Visual Studio 2010中正确引用dll? - How to correctly reference a dll in Visual Studio 2010? 如何在Visual Studio 2010中添加引用 - How to add a reference in Visual studio 2010 在XNA中,我如何正确参考与原点有关的vector2坐标? - in xna how do i properly reference the vector2 coordinates in relation to origin? 如何在Visual Studio 2013上使用Xna Content Compiler - How to use Xna Content Compiler on visual studio 2013
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM