2014-04-13 35 views
0

我正在XNA框架中進行遊戲。 由於某些原因,我在代碼中所做的更改不會更改遊戲。 它變得如此可笑我真的試圖驗證碼:我在代碼中所做的更改不會發生

protected override void Update(GameTime gameTime) 
    { 
     if (false) 
     { 
      // Allows the game to exit 
      if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) 
       this.Exit(); 
      ProcessNetworkMessages(); 
      if (!IsHost) 
      { 
       KeyboardState newState = Keyboard.GetState(); 
       localPlayer.Update(gameTime, oldState, newState, board); 
      } 
      base.Update(gameTime); 
     } 
    } 

和遊戲仍照常運行。

+1

...問題是?另外,請注意,沒有任何細節,我們不能幫你。 –

+0

的問題是爲什麼?爲什麼我所做的改變不會影響遊戲?你需要更多的細節?我只是讓更新方法無法訪問(如果(false))並且遊戲仍然正常運行。爲什麼以及如何解決它? – ByoTic

+0

可能是因爲你的代碼沒有正確編譯和執行,或者你的邏輯錯誤。 –

回答

0

我很驚訝沒有人在這裏有一個線索,一個明顯的錯誤...

一個if語句運行,如果答案是真的,如果答案是假的,而跳過。所以,如果你把錯誤,它顯然不會運行你的代碼。如果將其更改爲true,則無論如何它總是會運行您的代碼。直接將真或假直接放入if語句就像是註釋代碼行或不行。

protected override void Update(GameTime gameTime) 
    { 
     if (false) //<--- The answer is false, let's not run this code block! 
     { 
      // Allows the game to exit 
      if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) 
       this.Exit(); 
      ProcessNetworkMessages(); 
      if (!IsHost) 
      { 
       KeyboardState newState = Keyboard.GetState(); 
       localPlayer.Update(gameTime, oldState, newState, board); 
      } 
      base.Update(gameTime); 
     } // Start running code from here --> 
    } 

基本上,你沒有更新任何東西,這段代碼只是沒有運行。嘗試if語句內的換行符以查看它不運行。

相關問題