我使用lwjgl渲染遊戲環境,同時使用scene2d.UI來構建一個包含我的輸入的表。LIBGDX:如何在混合的2D/3D設置中攔截UI上的點擊?
目前,如果我點擊UI,它會做出反應,但遊戲環境也是如此。很明顯,因爲我沒有處理它。 這裏的問題是 - 其中應該處理輸入,以便在用戶界面上點擊鼠標不會激活環境的輸入處理。
我的想法是將偵聽器附加到UI表並將輸入處理移到偵聽器。我只是不知道如何設置。 我應該在表格上設置一個ClickListener,還是在兒童上,還是應該在這裏做些別的事情?
這是在渲染循環運行的方法:
private void processInput() {
//Handle user input here
//[...]
//Mouse input
if(Gdx.input.isButtonPressed(Input.Buttons.LEFT) && lastClick == null) {
//lastClick = new Vector2(Gdx.input.getX() + CameraOrigen().x, (CameraOrigen().y+camera.viewportHeight)-Gdx.input.getY());
lastClick = ScreenToWorld(new Vector2(Gdx.input.getX(),Gdx.input.getY()));
gridIntersect = WorldToTileCoord(lastClick);
}
else if (!Gdx.input.isButtonPressed(Input.Buttons.LEFT) && lastClick != null) { lastClick = null; }
}
這是我當前如何構建UI:
//------------- UI Construction ------------//
table.align(Align.top);
Table debugTable = new Table();
debugTable.add(debugMouseTable);
debugTable.add(debugTileSelectTable);
table.add(debugTable).expandX().height((float)(game.VIRTUAL_HEIGHT * 0.85));
table.add(spTest).width((float)(game.VIRTUAL_WIDTH * 0.2)).height((float)(game.VIRTUAL_HEIGHT * 0.85)).bottom();
table.row();
table.add(sbTileTypes).align(Align.left).expandY();
table.add("corner");
spDebug.pad(10).defaults().expandX().space(4);
for (AtlasRegion aReg : hmTiles.get(TileType.FLOOR)) {
spDebug.add(new Button_TilePreview(aReg, skin, sbTileTypes.GetSelectionValue(), this, brush));
spDebug.row();
}
spDebug.invalidateHierarchy();
//------------------------------------------//
好吧,我明白你在說什麼了。 我現在正在查看文檔,我認爲你讓我走上正軌。 感謝您的幫助:) – Kaezon
嗨,我理解多路複用器是如何工作的,如果舞臺可以處理輸入,它不會打擾請求gameplayinputprocessor處理輸入。那麼我應該讓舞臺覆蓋UI嗎?否則,它會進入遊戲區域並嘗試處理那裏的點擊嗎? – CandiedMango
閱讀此https://github.com/libgdx/libgdx/wiki/Scene2d現在明白了 – CandiedMango