【问题标题】:XNA / Monogame mouse input does not workXNA / Monogame 鼠标输入不起作用
【发布时间】:2017-06-01 11:08:07
【问题描述】:

我尝试对鼠标点击做出反应。我的问题是,它不起作用。即使是单击鼠标也不会被检测到。状态根本没有改变。 也许有人可以看到错误。 问候,马克斯

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

【问题讨论】:

    标签: c# xna monogame


    【解决方案1】:

    我认为您可能按下了错误的鼠标按钮。我知道我这样做了很多次。

    【讨论】:

    • 不幸的是,事实并非如此。 ://
    • 鼠标状态:MouseState mouse = Mouse.GetState();永不改变。
    • 我会将 MonoGame 更新到最新版本。这可能是一个错误。
    猜你喜欢
    • 2016-05-27
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-21
    相关资源
    最近更新 更多