我是XNA的新手,我开始遵循一个在屏幕上绘制图像的教程.我能够将我的图像移动到Content文件夹中,但是当我尝试在我的代码中使用它时,无法找到它.
我正在使用资产名称而我找不到我做错了什么.教程使用XNA 3.0,我使用的是Visual Studio 2010,不确定是否重要.
这是我的代码
public class Game1 : Microsoft.Xna.Framework.Game
{
Vector2 mPosition = new Vector2(0, 0);
Texture2D mSpriteTexture;
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
mSpriteTexture = Content.Load<Texture2D>("Face");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
spriteBatch.Draw(mSpriteTexture, mPosition, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
Run Code Online (Sandbox Code Playgroud)
}
错误显示"ContentLoadException未处理.未找到文件.
我希望这是足够的信息.我的文件的资产名称也是Face.
提前致谢.
如果您已经将您的文件内容项目(这些是新的4.0)其他需要检查的事项将是确保文件是对一个Texture2D支持的格式(为.jpg,.png .BMP之一. TGA).之后,单击图像并验证资产名称是否正确,并与您在代码中使用的确切大小写/拼写相匹配,以便按该名称加载它.如果这是正确的,那么还要确保图像的内容导入器正确设置为Texture2D.然后要验证的另一件事是确保您的图像位于Content项目的根目录中而不是文件夹中.如果将其放在文件夹中,则需要在加载文件夹时包含文件夹名称(或多个名称).
如果您已经验证了所有这些,那么您可能需要发布图像或示例项目,以便我们可以查看并查看是否我们发现了任何方式.
从该屏幕截图看起来您需要右键单击"测试"项目并说出"添加内容参考".然后,您需要选择"测试(内容)"项目作为该参考.这应该是在您创建这个新游戏项目时默认发生的,我不确定为什么它看起来像被删除了.