任何人都可以製作和編譯這個程序(Click here))直到第一個「快速構建」。?(直到他們說「這將是一個偉大的時間來做一個!快建「)XNA Windows遊戲(4.0)ContentLoadException
出於某種原因,我不斷收到此異常
我檢查這個#1方案中提到的一切:Click Here但沒有它解決了我的問題:(
我的形象是放置在「內容」區域中,它不位於文件夾中。
請幫忙!
這裏是我的代碼如下所示:
namespace myGame
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteBatch mBatch;
Texture2D mHealthBar;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
mBatch = new SpriteBatch(this.graphics.GraphicsDevice);
ContentManager aLoader = new ContentManager(this.Services);
**//ERROR occurs here!**
mHealthBar = aLoader.Load<Texture2D>("HealthBar") as Texture2D;
}
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
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);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
mBatch.Begin();
mBatch.Draw(mHealthBar, new Rectangle(this.Window.ClientBounds.Width/2 - mHealthBar.Width/2,
30, mHealthBar.Width, 44), new Rectangle(0, 45, mHealthBar.Width, 44), Color.Red);
//Draw the box around the health bar
mBatch.Draw(mHealthBar, new Rectangle(this.Window.ClientBounds.Width/2 - mHealthBar.Width/2,
30, mHealthBar.Width, 44), new Rectangle(0, 0, mHealthBar.Width, 44), Color.White);
mBatch.End();
base.Draw(gameTime);
}
}
}
您的問題*可能是您正在創建自己的ContentManager。嘗試使用:this.Content.Load(「HealthBar」) –
GGulati
2011-12-28 01:45:30
我試過這樣做,但它沒有解決問題....感謝反正 – BigBug 2011-12-28 04:03:34
如果您使用自己的ContentManager,您必須將RootDirectory屬性設置爲「內容「,或者如果你有不同的文件夾,那麼你可以將其設置爲。 – annonymously 2011-12-28 05:06:10