How to prevent mouse cursor moves ouside the screen?

my game is third-person game
the problem is that when I try to use mouse cursor(move it) to change the direction of camera, the mouse cursor always moves outside the window, that makes I can’t change the direction of camera anymore.
So, how to keep the mouse inside the screen? I want that when the mouse cursor touches to the edge of the screen, it begins to stop moving.
any ideas??
I have searched for a post who has similar problem with me, but I don’t quite understand it.
http://hub.jmonkeyengine.org/forum/topic/keep-mouse-cursor-inside-app-window/
many thanks

what don’t you understand in that :

@ said: Hi @claudeon,<br /> <br /> try to do the following (it is just one easy way of many ways from which some might be better):<br /> <br /> 1. Disable the cursor (there is actually a bug preventing this during initialization when disabling the flyCam, but ... )<br /> To do so, call the input managers setCursorVisibilty method with parameter false in your update method (there is no other overhead free way until the bug is fixed).<br /> <br /> 2. Create your own cursor as 2D image and provide a two dimensional vector for it.<br /> <br /> 3. You can now clamp this position to your window borders.<br /> <br /> 4. Register e.g. a raw input listener to your inputManager to react to mouseMotion events. Whenever the mouse moves, you adjust your own position vector of your own cursor.<br /> <br /> The advantage is, that your real mouse position can be anywhere in the window - you just don't care about it. You can now rely on your position stored in your own vector and do computations or other stuff with it.

You grab the mouse (=disable the cursor, as said) then create your own and handle yourself its movement. There may be other way to do so, and it will not work with nifty (not without some trick) but you are not at this point right now.

2 Likes