litiengine icon indicating copy to clipboard operation
litiengine copied to clipboard

Mouse Moves in Wrong Direction When Turning GrabMouse On

Open Hades948 opened this issue 1 year ago • 1 comments

Describe the bug When I call Input.mouse().setGrabMouse(true), the mouse moves in the wrong direction.

I want the player to be able to turn grab mouse on and off, so they can get out of the window without completely closing the game. When I turn grab mouse off, I figure out where the game mouse is and I use a robot to move the actual mouse to that location after calling setGrabMouse(false). This works fine. But when I turn grab mouse on, I'd expect the game mouse to stay where it is (or at the very least, return to the center of the screen). But, instead, it seems to be moving the distance between it and the center of the window, but in the wrong direction.

I believe this is happening in Mouse.setLocation(MouseEvent): image

This is, of course, the correct behavior when grab mouse is on. But I think it's incorrect when grab mouse was off during the last update, but is now on. Again, in that case, I think I'd expect the game mouse's position to just stay where it is (even if the mouse is moving back to the center of the screen).

Here's a GIF where I try to demo it, but it's a little hard to show. Details on how to reproduce are below. java_4ZbXZ7ULbt

To Reproduce Steps to reproduce the behavior:

  1. Throw this code in your main() or somewhere: image VirtualMouse.instance().getLocationOnScreen() does the following: image Utils.robot is just a normal Robot object.

  2. Run the game and press Alt to release the mouse.

  3. Click somewhere on the screen. Closer to the middle is easier to see what's happening. The game mouse will jump away from the center of the screen.

Your System:

  • OS: [e.g. iOS]
  • LITIENGINE version: 0.6.1
  • Java JDK/JRE version: jdk-21.0.1
  • Screen resolution: 4K

Btw, I welcome feedback on this code. I haven't worked with the mouse and robots much.

Hades948 avatar Feb 24 '24 16:02 Hades948

Thanks for the elaborate example! Will check this out when I'm back from vacation in March.

nightm4re94 avatar Feb 24 '24 17:02 nightm4re94