我在xna begginer,我可以加載一個圖像,但它不工作,拋出一個異常,沒有找到文件,我已經嘗試了一切衝浪每一個地方,很多人問,疑問句,無法找到答案,請幫忙,這裏的IM在很大的麻煩是代碼無法加載圖像在xna
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);
}
圖像中添加內容
你需要提供更多的細節:拋出什麼異常,哪些文件找不到?哪個函數是錯誤的? – Barmar
您是否已將「AssetName」「gray」圖片添加到您的內容項目中? –
是內容加載器集的根文件夾? – Markus