2014-02-10 25 views
0

我是XNA遊戲開發的新品牌,目前正在練習製作遊戲。遊戲項目未在XNA建設後啓動

我開始創建一個簡單的平臺遊戲,並慢慢建立了遊戲和遊戲功能的邏輯。我最近的加入似乎已經打破了這個項目。它在添加健康欄功能後開始,我添加了11個紋理(健康欄空,健康欄1/10,健康欄2/10等)。

當玩家在遊戲中遇到諸如尖刺這樣的有害物體時,爲健康狀態欄顯示的紋理會發生變化(因此如果健康狀態欄位於9,則紋理會變爲healthBar8)。

該問題是由於在兩個不同的Visual Studio窗口中打開了兩個相同的項目而導致項目生成的實際錯誤。 (這對我來說太愚蠢了,我在搜索到兩個窗口打開之前如何解決給定的錯誤)。建議的修復是,進入預生成命令行中的這些兩行:是否存在 「$(TARGETPATH).locked」 DEL 「$(TARGETPATH).locked」 是否存在「$

(TARGETPATH)」如果不存在 「$(TARGETPATH).locked」 移動 「$(TARGETPATH)」 「$(TARGETPATH).locked」

這似乎已經解決了這一錯誤,但現在只有我的項目構建並且不啓動,所以我關閉了額外的窗口,我發現我已經打開並從預構建命令行框中移除了兩行,但現在該項目只是構建並且doe不會發射。

我試着創建一個新項目,並檢查它是否構建(它確實如此,因此Visual Studio本身不是問題),然後將破碎項目的代碼複製並粘貼到這個新項目中,該項目仍未啓動。

我不知道這是什麼原因造成的,這是非常煩人的。如果我的問題陳述得不好,我真的很抱歉,因爲這是我的第一個Stack溢出問題(因爲我從來沒有覺得需要在互聯網上實際發佈問題),但是在廣泛的谷歌搜索之後我找不到解決方案。

public class MainGame : Microsoft.Xna.Framework.Game 
{ 
    GraphicsDeviceManager graphics; 
    SpriteBatch spriteBatch; 
    SpriteFont coinCount; 

    List<PlatformSprite> platformsList; 
    List<Consumable> pickUpList; 
    List<StaticEnemy> staticEnemyList; 

    //public Texture2D currentHealthTexture; 
    //Texture2D healthEmpty; 
    //Texture2D health1; 
    //Texture2D health2; 
    //Texture2D health3; 
    //Texture2D health4; 
    //Texture2D health5; 
    //Texture2D health6; 
    //Texture2D health7; 
    //Texture2D health8; 
    //Texture2D health9; 
    //Texture2D healthFull; 

    //List<Texture2D> healthBarsList; 

    Texture2D coinAnim; 
    Texture2D coinAnimBig; 
    Texture2D floatingPlatform; 
    Texture2D groundPlatform; 
    Texture2D redPlayer; 
    Texture2D spikeEnemy; 

    Rectangle destRect; 
    Rectangle sourceRect; 
    Rectangle destRectSmall; 
    Rectangle sourceRectSmall; 

    PlayerSprite player; 
    KeyboardState keyboardState; 

    float elapsed; 
    float delay = 90f; 
    int frameCount = 0; 

    public const int screenHeight = 550; 
    public const int screenWidth = 800; 

    public MainGame() 
    { 
     graphics = new GraphicsDeviceManager(this); 

     graphics.PreferredBackBufferHeight = screenHeight; 
     graphics.PreferredBackBufferWidth = screenWidth; 

     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() 
    { 
     destRect = new Rectangle(100, 100, 60, 60); 
     destRectSmall = new Rectangle(100, 300, 20, 20); 
     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); 

     coinCount = Content.Load<SpriteFont>("CoinCount"); 

     platformsList = new List<PlatformSprite>(); 
     pickUpList = new List<Consumable>(); 
     //healthBarsList = new List<Texture2D>(); 
     staticEnemyList = new List<StaticEnemy>(); 

     coinAnim = Content.Load<Texture2D>("CoinSpinAnim"); 
     coinAnimBig = Content.Load<Texture2D>("CoinAnim"); 
     floatingPlatform = Content.Load<Texture2D>("Platform1"); 
     groundPlatform = Content.Load<Texture2D>("GroundPlatform1"); 
     redPlayer = Content.Load<Texture2D>("TestSprite"); 
     spikeEnemy = Content.Load<Texture2D>("Spike"); 

     //healthEmpty = Content.Load<Texture2D>("HealthBarEmpty"); 
     //health1 = Content.Load<Texture2D>("HealthBar1"); 
     //health2 = Content.Load<Texture2D>("HealthBar2"); 
     //health3 = Content.Load<Texture2D>("HealthBar3"); 
     //health4 = Content.Load<Texture2D>("HealthBar4"); 
     //health5 = Content.Load<Texture2D>("HealthBar5"); 
     //health6 = Content.Load<Texture2D>("HealthBar6"); 
     //health7 = Content.Load<Texture2D>("HealthBar7"); 
     //health8 = Content.Load<Texture2D>("HealthBar8"); 
     //health9 = Content.Load<Texture2D>("HealthBar9"); 
     //healthFull = Content.Load<Texture2D>("HealthBarFull"); 
     //healthBarsList.Add(healthEmpty); 
     //healthBarsList.Add(health1); 
     //healthBarsList.Add(health2); 
     //healthBarsList.Add(health3); 
     //healthBarsList.Add(health4); 
     //healthBarsList.Add(health5); 
     //healthBarsList.Add(health6); 
     //healthBarsList.Add(health7); 
     //healthBarsList.Add(health8); 
     //healthBarsList.Add(health9); 
     //healthBarsList.Add(healthFull); 

     platformsList.Add(new PlatformSprite(groundPlatform, new Vector2(0, 454))); 
     platformsList.Add(new PlatformSprite(floatingPlatform, new Vector2(500, 330))); 
     platformsList.Add(new PlatformSprite(floatingPlatform, new Vector2(100, 290))); 
     platformsList.Add(new PlatformSprite(floatingPlatform, new Vector2(300, 250))); 
     platformsList.Add(new PlatformSprite(floatingPlatform, new Vector2(170, 250))); 
     platformsList.Add(new PlatformSprite(floatingPlatform, new Vector2(350, 360))); 

     staticEnemyList.Add(new StaticEnemy(spikeEnemy, platformsList[0], 300)); 

     pickUpList.Add(new Consumable(coinAnim, platformsList[1], 30, sourceRectSmall)); 
     pickUpList.Add(new Consumable(coinAnim, platformsList[3], 45, sourceRectSmall)); 
     pickUpList.Add(new Consumable(coinAnim, platformsList[4], 60, sourceRectSmall)); 

     player = new PlayerSprite(redPlayer, platformsList, pickUpList, staticEnemyList, 0); 
    } 

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

     keyboardState = Keyboard.GetState(); 

     //currentHealthTexture = healthBarsList[player.playerHealth]; 

     player.Update(keyboardState); 

     elapsed += (float)gameTime.ElapsedGameTime.TotalMilliseconds; 

     if (elapsed >= delay) 
     { 
      if (frameCount >= 5) 
      { 
       frameCount = 0; 
      } 
      else 
      { 
       frameCount++; 
      } 

      elapsed = 0; 
     } 

     sourceRect = new Rectangle(60 * frameCount, 0, 60, 60); 
     sourceRectSmall = new Rectangle(20 * frameCount, 0, 20, 20); 

     foreach (Consumable c in pickUpList) 
     { 
      c.Update(); 
     } 

     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); 

     spriteBatch.Begin(); 

     foreach (PlatformSprite p in platformsList) 
     { 
      p.Draw(spriteBatch); 
     } 

     foreach (Consumable c in pickUpList) 
     { 
      c.Draw(spriteBatch, sourceRectSmall); 
     } 

     foreach (StaticEnemy se in staticEnemyList) 
     { 
      se.Draw(spriteBatch); 
     } 

     //spriteBatch.Draw(currentHealthTexture, new Vector2(680, 10), Color.White); 

     spriteBatch.DrawString(coinCount, ": " + player.playerCoinCount, new Vector2(30, 10), Color.White); 
     spriteBatch.Draw(coinAnim, new Rectangle(10, 10, 20, 20), new Rectangle(0, 0, 20, 20), Color.White); 


     player.Draw(spriteBatch); 

     spriteBatch.End(); 

     base.Draw(gameTime); 
    } 
} 

正如你可以看到我已經註釋掉所有健康條碼的,我希望這增加了細節,我的問題,但真的很抱歉,如果這是一個可怕的問題,我只是不知道該怎麼做或者開始修復它。

臨時更新 - 固定它! :D

我把它縮小到一個while循環,導致這種「構建但不啓動」的錯誤。我嘗試了幾次評論循環,然後再次將它帶回桌面,並且每次我評論它成功啓動遊戲。我在我的手機上知道所以我很抱歉沒有引用確切的循環,但它是一個while循環,如下所示: int j:0;同時(j < staticEnemyList.Count) if(player.enclosedRectangle.Intersects(staticEnemyList [i])。GetRectangle)){ playerHealth-- } 其他 { J ++ }}

我認爲這是與設置的敵人名單指數的 '我',而不是Ĵ但這並沒有返回一個錯誤,因爲我在這個基於一個名爲'i'的整數之前有一個循環。仍然沒有線索,爲什麼這個while循環打破了視覺工作室,任何建議會很酷?我再次對我的可怕格式等抱歉,只要我在我的電腦上,我會更新實際的循環代碼。感謝大家誰評論,偉大的建議 - 再次...對不起 - 真的很難評論電話,我不能在8小時內回答,這只是暫時的:)

+0

呃哦,如何按年格式 – ImperialCoder

+0

你試過關掉它嗎? – Cemafor

+0

不妨嘗試一下,沒有別的工作。 – ImperialCoder

回答

0

項目建成,但沒有出現,因爲我錯誤地創建了一個愚蠢的無限循環。這是通過創建幾個不同的整數並且不使用正確的整數和相應的while循環來完成的。一個簡單的問題確實很容易解決,但對於剛接觸C#的人來說,這看起來確實很嚇人。