XNA / Monogame鼠标输入不起作用

时间:2017-06-01 11:08:08

标签: c# xna monogame

我只想点击鼠标做出反应。我的问题是,它不起作用。即使是单个鼠标点击也不会被检测到。国家根本没有变化。 也许有人可以看到错误。 问候,Max

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 :(得分:1)

我想你可能会按错了鼠标按钮。我知道我做了很多次。