[SOLVED] Hiding the Mouse Cursor

Today I decided to implement a custom animated cursor into my jME project and ran into some problems hiding the default cursor. I was able to solve this problem and being as how I was not able to find a solution on-line I decided I should post my solution here in the event others might find it useful.

First a brief description of the issues I encountered. My goal was to attach a quad to the guiNode and then just set its location to the cursor’s screen position, this was not a problem. Of course there was the need to hide the operating system’s cursor. A simple inputManager.setCursorVisible(false) seems like a good solution, but you might be surprised. First of all, if you use flyCam.setEnabled(false) the aforementioned call to inputManager.setCursorVisible(false) will not work, you need to detach the flyCam appState from the State Manager instead:


Once this is done inputManager.setCursorVisible(false) will work, however, now that the cursor is hidden there are two problems I encountered. First, NiftyGUI ceased to recognize mouse input events! Second, when running in windowed mode the cursor would not leave the window so it wasn’t possible to close the game via the window decoration’s close button, not a big deal, but not that great either. At any rate Nifty not recognizing mouse events was, obviously, quite a problem for me.

Instead of hiding the cursor I set the cursor to a transparent image. This solved both of the above problems. Not only does Nifty still receive mouse events, the cursor can leave the screen in windowed mode at which point it becomes visible again so there’s a rather seamless integration with the desktop. Here’s a simple method of accomplishing this in simpleInitApp:

JmeCursor jCursor = new JmeCursor();
int[] i = new int[16 * 16];
Arrays.fill(i, 0);

P.S. When using inputManager.setCursorVisible(false) I’m not really sure if the cursor wouldn’t leave the screen or not, if it did it was invisible and the desktop was not interacting with it at all. This is in Win7 32-bit.


Yo @Tryder,

yeppers, I totally hear ya on the whole “finding the relevant info on what we are trying to do” thing. Just doing a cross link for those who like videos n stuff.

A Couple of Application Tweaking Video Tips for jMonkeyEngine

The second video on the page shows the concept of changing the cursor. The method I was referring in the video supports .ani and .cur formats, if I remember rightly.

Game On,

1 Like

Great tutorial Relic724. I had considered doing a cursor that way, but the cursor I made uses semitransparent areas which are not supported with JmeCursor, it’s either transparent or not.

I rendered it in Blender cycles and it has a sorta shadow type effect to help distinguish it in both light and dark areas. Has a nice 36 frame rotating animation.