有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java从JMonkey窗口解锁鼠标

通常情况下,鼠标锁定在窗口,不可见;以第一人称射击的方式控制摄像机

我的理解是,您可以从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行为(无与伦比)


共 (3) 个答案

  1. # 1 楼答案

    解决办法似乎是还必须禁用flycam。所以

    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);
        }
    
    }
    
  2. # 2 楼答案

    或者简单地说:

    flyCam.setDragToRotate(true);
    
    inputManager.setCursorVisible(true);
    

    flyCam仍然可以打开

  3. # 3 楼答案

    禁用FlyCam是实现这一点的一种方法,但更好的方法是从不首先添加它。如果你为你的应用程序创建了一个新的构造函数,并调用了第二个SimpleApplication构造函数,你可以传入一个要使用的应用程序状态列表,这些状态完全取代了标准集,这样你就可以选择你想要的