2017-06-01 92 views
1

我只是試圖通過點擊鼠標來做出反應。我的問題是,它不起作用。即使是單擊鼠標也不會被檢測到。國家根本沒有改變。 也許有人會看到錯誤。 問候,最大XNA/Monogame鼠標輸入不起作用

using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Graphics; 
using Microsoft.Xna.Framework.Input; 
using EvoSim.Map; 


namespace EvoSim 
{ 
    /// <summary> 
    /// This is the main type for your game. 
    /// </summary> 
    public class EvoSim : Game 
    { 
     private GraphicsDeviceManager graphics; 
     private SpriteBatch spriteBatch; 
     private TileMap map; 

     public EvoSim() 
     { 
      graphics = new GraphicsDeviceManager(this); 
      // graphics.IsFullScreen = true; 
      graphics.PreferredBackBufferWidth = 1920; // set this value to the desired width of your window 
      graphics.PreferredBackBufferHeight = 1082; // set this value to the desired height of your window 
      graphics.ApplyChanges(); 

      System.Console.WriteLine("Active:" + this.IsActive); 
      Content.RootDirectory = "Content"; 
      IsMouseVisible = true; 

     } 


     protected override void Initialize() 
     { 
      spriteBatch = new SpriteBatch(GraphicsDevice); 
      map = new TileMap(500, 500, 8, GraphicsDevice); 

      map.Initialize(); 
      base.Initialize(); 
     } 


     protected override void LoadContent() 
     { 
      Tiles.Content = Content; 
      map.Generate(); 
     } 


     protected override void UnloadContent() 
     { 

     } 


     protected override void Update(GameTime gameTime) 
     { 
      if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) 
       Exit(); 
      MouseState mouse = Mouse.GetState(); 
      if (mouse.RightButton == ButtonState.Pressed) 
      { 
       System.Console.WriteLine("Click"); 
       Exit(); 
      } 
      map.Update(gameTime); 
      base.Update(gameTime); 
     } 


     protected override void Draw(GameTime gameTime) 
     { 
      GraphicsDevice.Clear(Color.CornflowerBlue); 
      map.Draw(spriteBatch); 
      base.Draw(gameTime); 
     } 
    } 
} 

回答

1

我想你可能會按錯了鼠標。我知道我做了很多次。

+0

不幸的是,情況並非如此。 :/ – Max

+0

鼠標狀態:MouseState mouse = Mouse.GetState();從不改變。 – Max

+0

我會將MonoGame更新到最新版本。這可能是一個錯誤。 – MessLuke