Hi all… is there any way to set a cursor position (x,y) in JME? i want to prevent my cursor from getting outside the app window when i move it to the edge of the app window… thanks
Just so you know, forcing the mouse inside a windowed-mode application is often considered bad form.
woahh thanks for the info but aside from that, could it be done? ive tried using Robot class with mouseMove method, but the coordinate was relative to my monitor screen… can i change it so the coordinate will relative to my app screen? thankss
Newer Windows versions (i.e. anything after Win95) do not allow that.
Not just because it’s bad form but because it would allow an application to capture the mouse in a 1x1 “jail window” and render the computer inaccessible.
(Alt-Tab, Alt-Esc, Ctrl-Alt-Del and a few other critical key combos can’t be disabled or even received for similar reasons.)
What do you wish to achieve?
try to do the following (it is just one easy way of many ways from which some might be better):
- Disable the cursor (there is actually a bug preventing this during initialization when disabling the flyCam, but … )
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).
- Create your own cursor as 2D image and provide a two dimensional vector for it.
- You can now clamp this position to your window borders.
- 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.
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.
hi, @toolforger :)…
im trying to keep my mouse visible so i can click an object to do something… in my case, i want to make a building on the the place ive clicked… and if i move my cursor to the windows edge, i want my camera to move according to which side my cursor collide… i dont use full screen because im afraid it would mess my GUI
hi, @universe :)…
honestly, i dont really get some of your tips… sorry for my lacks of knowledge but perhaps a code example would help me understanding everything that u told me
thanks for both of you!
Hmm… that’s a nice thing you want to achieve, @claudeon. I think I’ll want that for myself.
I’d do it by always showing the mouse, but let the viewing angle turn faster and faster as the mouse approaches the window border.
E.e. when the mouse is going from center to border:
- between 0% and 50%, don’t change the viewing angle (this is the “dead zone”);
- 50% and 100%, ramp up the rotation speed for the viewing angle from zero to, say, 90 degrees per second.
- outside the window, don’t turn the viewing angle anymore.
You may want to experiment with the actual size of the central dead zone, and the maximum rotation speed (turn too fast and people could get dizzy).
Also, you may want to introduce a latency before turning starts, so if somebody moves the mouse outside the window quickly, they don’t start the window turning.
Let me know if anything was unclear.