简体   繁体   English

java lwjgl如何使鼠标不可见

[英]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. 我正在制作3D游戏,并且我刚刚能够使用鼠标移动摄像头,然后将鼠标放回中心。 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); 我以为会有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 我正在为Java使用LWJGL 2

You can do it with LWJGL 3 as follows: 您可以使用LWJGL 3进行以下操作:

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: 还要将其保留在窗口中,类似于LWJGL 2的抓取模式:

glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

To revert its state back to normal: 要将其状态恢复为正常:

glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);

You can use the Mouse.setGrabbed(true) method to "hide" the cursor and keep it inside your window. 您可以使用Mouse.setGrabbed(true)方法“隐藏”光标并将其保留在窗口内。 Just be aware that you need to call Mouse.create() once during setup, and Mouse.destroy() before exiting the game. 要知道,你需要调用Mouse.create()在安装过程中一次, Mouse.destroy()退出比赛之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM