好吧,所以我是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