java - 从 JMonkey 窗口解锁鼠标

标签 java mouse jmonkeyengine

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

我的理解是您从 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/

相关文章:

python - 在 Pygame 窗口中锁定鼠标

c# - 单击中键可滚动

java - jMonkey优化类似于Java3D的

java - 如何在 JMonkey 引擎库中画一条直线

java - 重新创建数组

java - 没有 OpenGL、DirectX、XNA 等的 3D 图形理论和代码

java - ClassLoader.getSystemResourceAsStream 和 getClass().getResourceAsStream() 的区别

java - 存储应用程序设置而不是使用首选项

javascript - 使用 jQuery 设置动画时丢失悬停(不移动鼠标)

java - jMonkeyEngine - 像在第一人称游戏中一样用鼠标旋转