Libgdx:对话框不侦听输入



我的目标是向用户显示一个对话框,以便他能够选择将哪个Actor添加到Stage。我在实现Screen和GestureListener的应用程序的主屏幕中执行此操作。(我需要GestureListener来收听双击)。我在重写的touchDown()方法中创建了对话框。当对话框出现时,它不起作用。如果我点击屏幕的任何一点,屏幕将继续监听touchDown中的输入。

这是代码:

public class SquareDefense implements Screen, GestureListener {
    ....
    @Override
    public boolean touchDown(float x, float y, int pointer, int button) {
        System.out.println("touchDown");
        if(squareDefenseTable.getActor(x, y) != null) {
            // rotate the clicked actor!
            squareDefenseTable.rotateActor(x, y);
        }
        else {
            showDialog();
        }
        return true;
    }
    private void showDialog() {
        Dialog dialog = new Dialog("Choose an action", skin) {
            @Override
            protected void result(Object object) {
                boolean exit = (Boolean) object;
                if (exit) {
                    Gdx.app.exit();
                } else {
                    remove();
                }
            }
            @Override
            public Dialog show(Stage stage) {
                return super.show(stage);
            }
            @Override
            public void cancel() {
                super.cancel();
            }
            @Override
            public float getPrefHeight() {
                return 50f;
            }
        };
        dialog.button("Yes", true);
        dialog.button("No", false);
        dialog.key(Input.Keys.ENTER, true);
        dialog.key(Input.Keys.ESCAPE, false);
        dialog.show(stage);
    }
}

我想你错过了添加这行代码:

Gdx.input.setInputProcessor(stage);

告诉我是否可以

最新更新