我是xna中的begginer,我试图加载一个图像,但它没有工作,抛出一个异常,找不到文件,我已经尝试过每个地方冲浪,很多人问那个问题,找不到答案请帮助,我很麻烦这里是代码
protected override void Initialize()
{
base.Initialize();
}
/// <summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
mytexture = Content.Load<Texture2D>("gray");
myrectangle = new Rectangle(100, 100, 40, 40);
// TODO: use this.Content to load your game content here
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
spriteBatch.Draw(mytexture, myrectangle , Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
图片已添加到内容
中答案 0 :(得分:0)
问题是文件已被删除或移动,并且您的内容项目无法再找到该文件。
查看您的内容项目下的图像列表。您很可能在根目录中没有一个名为gray的颜色。如果它在那里,你可以检查一些事情:
答案 1 :(得分:0)