2013-12-17 31 views
1

通常鼠標被鎖定到窗口並且不可見;以第一人稱射擊者的風格控制相機。從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行爲(unsurpisingly)

回答

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); 
    } 

} 
1

禁用FlyCam是做到這一點的一種方式,但更好的方法是從來沒有將它添加在首位。如果您爲您的應用程序創建了一個新的構造函數,並調用SimpleApplication的第二個構造函數,那麼您可以傳入要使用的應用程序狀態列表,並且這些應用程序狀態將完全替換標準集,以便您可以精確選取所需的。

+0

對於我的使用情況下,我需要,所以我需要它有時模式之間移動。這可能對其他情況有用 –

+0

您可以動態地添加和刪除應用程序狀態,但是在您的情況下,根據需要啓用和禁用它可能會更好。 –

-1

或者乾脆:

flyCam.setDragToRotate(true); 

inputManager.setCursorVisible(true); 

的flyCam仍然可以在

+0

這會起作用,但會導致dragToRotate行爲進入。特別是如果您有任何「單擊並拖動」行爲,則它無法正常工作 –