0
votes

I try just to react on a mouse click. My problem is, that it does not work. Even a single mouseclick would not be detected. The state doesn't change at all. Maybe somebody can see the fault. Greetings, 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

1 Answers

1
votes

I think you might be pressing the wrong mouse button. I know I did that many times.