2017-06-01 50 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