user6053405
user6053405

Reputation:

java lwjgl how to make the mouse invisible

I am making a 3D game and I have just got the ability to allow the mouse to move the camera and then put the mouse back to the centre. But I want don't want the user to see an annoying mouse at the centre of the screen! So what I'm asking is: how do I make the mouse invisible? / how do I make the cursor disappear? I thought that there would be a Mouse.setVisible(false); but doesn't seem to exist. Thanks in advance. Also I want to do it without making a blank image. I'm using LWJGL 2 for java

Upvotes: 3

Views: 3400

Answers (2)

javac
javac

Reputation: 2441

You can do it with LWJGL 3 as follows:

To hide the cursor but make it able to leave the window:

glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);

To keep it in the window as well, similar to LWJGL 2's grabbed mode:

glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

To revert its state back to normal:

glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);

Upvotes: 7

CConard96
CConard96

Reputation: 914

You can use the Mouse.setGrabbed(true) method to "hide" the cursor and keep it inside your window. Just be aware that you need to call Mouse.create() once during setup, and Mouse.destroy() before exiting the game.

Upvotes: 2

Related Questions