好吧,所以我是XNA的新手,我只是想让图像显示在屏幕上。我相信我已经将图像添加到VS2010程序中的内容文件夹,但是当我尝试运行该程序时,出现错误,提示文件未找到。所以我想知道什么文件夹有图像,只能调用图像文件Tank.png。 的代码很简单:XNA文件夹层次
namespace Aceldama_Windows_Game
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Vector2 mPosition = new Vector2(0, 0);
Texture2D mSpriteTexture;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
mSpriteTexture = this.Content.Load<Texture2D>("Tank");
}
/// <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();
spriteBatch.Draw(mSpriteTexture, mPosition, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
我应该把图像转换成能够调用该文件夹什么直接,而不必把完整的文件路径?本质上问题在于,无论我在哪里放置tank.png文件(无论它位于具有可执行文件/ c#文件的文件中还是位于内容文件夹中),似乎都好像无论在哪里。
尝试将其更改为:'mSpriteTexture = this.Content.Load(“Tank”);' –
aligray
2011-06-11 00:08:54
我也是这么做的,也是同样的问题。错误是找不到文件 – Zieklecknerizer 2011-06-11 00:36:32