2013-10-09 43 views
0

我正在爲XNA/Monogame編程Tower Defense遊戲,並且一直很好,直到我遇到了這個異常「FileNotFoundException」(當我得到其中一個時,它已被設置爲中斷,並且當我繼續時它不起作用)。它說它找不到添加的新圖像。我把它們放在內容文件夾中,根目錄設置爲內容。舊圖像的工作,但新的圖像不會。這是我的Game1.cs(這是我第一次編程非文字遊戲,所以它的有點亂(誤差在loadcontent功能發生)爲什麼我的紋理不能在Monogame/XNA中找到?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Audio; 
using Microsoft.Xna.Framework.Content; 
using Microsoft.Xna.Framework.GamerServices; 
using Microsoft.Xna.Framework.Graphics; 
using Microsoft.Xna.Framework.Input; 
using Microsoft.Xna.Framework.Media; 
//using Microsoft.Xna.Framework.Net; 
using Microsoft.Xna.Framework.Storage; 
using Microsoft.Xna.Framework.Input.Touch; 
using System.Diagnostics; 

namespace KillTheBugs2 
{ 
    /// <summary> 
    /// This is the main type for your game 
    /// </summary> 
    public class Game1 : Microsoft.Xna.Framework.Game 
    { 
     public Texture2D background; 
     public GameTime gameTime; 
     public Vector2 p; 
     Level level = new Level(); 
     public Player player; 
     public Ant ant1; 

     SpriteBatch _spriteBatch; 
     public GraphicsDeviceManager _graphics; 


     public Game1() 
     { 

      _graphics = new GraphicsDeviceManager(this); 

      _graphics.PreferredBackBufferWidth = 2000; 
      //This is wierd i will have to replace 32 with the size in pixels of 1 tile for some reason 
      _graphics.PreferredBackBufferHeight = 32 + 2500; 
      _graphics.ApplyChanges(); 
      IsMouseVisible = true; 
     } 

     /// <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() 
     { 

      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() 
     { 
      _spriteBatch = new SpriteBatch(GraphicsDevice); 
      Content.RootDirectory = "Content"; 
//background, ant, and blueberry bush wont load 
      background = Content.Load<Texture2D>("background"); 

      Texture2D AntTexture = Content.Load<Texture2D>("ant"); 
      ant1 = new Ant(AntTexture, Vector2.Zero, 100, 10, 0.5f); 
      Texture2D BlueberryBushTexture = Content.Load<Texture2D>("blueberrybush"); 
      player = new Player(level, BlueberryBushTexture); 




      // 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) 
     { 
      ant1.Update(gameTime); 
      List<Bug> bugs = new List<Bug>(); 
      bugs.Add(ant1); 

      player.Update(gameTime, bugs); 

      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(); 
      level.Draw(_spriteBatch, ref background); 
      ant1.Draw(_spriteBatch); 
      player.Draw(_spriteBatch); 
      _spriteBatch.End(); 

      base.Draw(gameTime); 
     } 
    } 
} 
+1

新圖片在屬性中是否也標記爲內容? – user2737037

回答

2

馬克的新圖像添加到該項目爲Build ActionContent在圖片的屬性菜單,通常在右側

+0

我在哪裏將其更改爲內容? – Detinator10

+0

我不介意我改變了它 – Detinator10

+0

謝謝你的存在快速回應 – Detinator10

相關問題