I am using MonoGame 3.6.0.906 on MacOS. I am trying to get some mouse input code working, but I have found some strange behaviour. It appears that the mouse position does not update when the left button is pressed. This makes it impossible to implement mouse dragging input.
To investigate, I added print statements when the left mouse button is pressed, when is released and the mouse position every update. I then tried clicking and dragging. The mouse definitely moved when the left button was down.
Here is the log:
...
{X:89 Y:384}
{X:89 Y:385}
{X:90 Y:386}
pressed
released
{X:91 Y:386}
{X:94 Y:386}
{X:96 Y:386}
...
As can be seen, the mouse position does not change when the left button is down.
Why is this? Is this a bug in MonoGame?
The important code:
MouseState previousMouseState;
protected override void Update(GameTime gameTime)
{
var mouseState = Mouse.GetState();
if (mouseState.LeftButton == ButtonState.Pressed &&
previousMouseState.LeftButton == ButtonState.Released)
{
Console.WriteLine("pressed");
}
if (mouseState.LeftButton == ButtonState.Released &&
previousMouseState.LeftButton == ButtonState.Pressed)
{
Console.WriteLine("released");
}
if (mouseState.Position != previousMouseState.Position)
{
Console.WriteLine(mouseState.Position);
}
previousMouseState = mouseState;
base.Update(gameTime);
}
Update I just tested this in a MonoMac application and it works correctly. The problem occurs when using the cross platform desktop template, the Xamarin Mac template and the Xamarin Classic template.