gpt4 book ai didi

java - 从 JMonkey 窗口解锁鼠标

转载 作者:太空宇宙 更新时间:2023-11-04 07:10:57 26 4
gpt4 key购买 nike

通常情况下,鼠标被锁定在窗口上并且不可见;以第一人称射击游戏的风格控制相机。

我的理解是您从 JMonkey 窗口解锁鼠标并通过调用使其可见

inputManager.setCursorVisible(true);

但是这没有明显的效果。以下示例程序对此进行了演示:

public class Main extends SimpleApplication {

public static void main(String[] args) {
Main app = new Main();
app.start();
}

@Override
public void simpleInitApp() {
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry("Box", b);

Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
inputManager.setCursorVisible(true);

rootNode.attachChild(geom);
}

}

调用flyCam.setDragToRotate(true);会解锁鼠标,但也会导致许多 DragToRotate 行为(不出所料)

最佳答案

这个问题的解决方案似乎是飞行摄像头也必须被禁用。所以

inputManager.setCursorVisible(true);
flyCam.setEnabled(false);

或者作为完整的示例

public class Main extends SimpleApplication {

public static void main(String[] args) {
Main app = new Main();
app.start();
}

@Override
public void simpleInitApp() {
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry("Box", b);

Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
inputManager.setCursorVisible(true);
flyCam.setEnabled(false);
//flyCam.setDragToRotate(true);
inputManager.setCursorVisible(true);
rootNode.attachChild(geom);
}

}

关于java - 从 JMonkey 窗口解锁鼠标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20639907/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com