I have issues with mouse locking. I would like to lock the mouse to the current position when I right click. My approach was to set the position to the locked position at the end of every frame and to use relative mouse positions for rotating. But the rotation is not very smooth, i have the impression that I loose mouse updates with this approach. But I have no idea how to solve it in a different way.
How about making a custom cursor class.
It would draw the cursor on draw() and update the position on update(). Adding a simple property for when the cursor is allowed to move would fix your problem.
Would not help. When I run in window mode I would reach the end of the screen and then the rotation would stop. I hide the cursor while rotating, so the cursor is not an issue.
Hey Sebastian. I would recommend using Cursor.Clip, from System.Windows.Forms. Clip will limit mouse movement in the screen by given rectangle. Only problems is that if player decides to minimize your game, or press something like Ctrl+Esc it will remove the clip. So your best option would be to track when the application is in focus again and reassign clip. Also don’t forget to change clip when window is moved or resized.
Try adding to you main update function and see how it works (just don’t leave it there). I would not use this if you are in the main menu, because then there won’t be any way to move or resize the window properly.
It solves one part of the problem. But what I would also like to achieve is to still get relative mouse positions while the cursor is locked.
I press the right mouse button and would like to rotate my camera until the mouse would fall down from the desk, but it stops when the end of my screen/monitor is reached.
When I reset the mouse to the viewport center I loose updates (perhaps rounding issues or so).
My only solution I found so far is to reset the position every 30 frames only and ignore this frame.
Well the difference is that my solution won’t ignore any frames, it is consistent that way. About not working with MonoGame I believe it has something to do about when it gets information about mouse position. If I understand correctly not working from you means not moving, if that so, then MonoGame sets Mouse position at the end of the updates. Honestly I have no idea
I just tried that with my minimal example and everything’s still working fine.
My guess would be that because of potentially higher fps some part in your code is the problem. E.g. not multiplying by deltatime or something