I am very new to XNA and I began by following a tutorial that draws an image on the screen.
I was able to move my image into the Content folder but when I try to use it in my code, it can't be found.
I am using the asset name and I just cannot find what I am doing wrong.
The tutorials use XNA 3.0 and I am using Visual Studio 2010, not sure if that matters or not.
Here is my code
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);
}
}
}
The error reads "ContentLoadException was Unhandled. File not found.
Solution Explorer
I hope this is enough information. Also the asset name of my file is Face.
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…