每次按下BACK或SCAPE键时,我都会尝试显示一个对话框。然而,事件只被捕获过一次,会显示对话框,但如果我按"否"按钮关闭它,那么它将永远不会再次出现,直到我转到另一个屏幕。
这就是我捕捉KeyUp事件的方式:
@Override
public boolean keyUp(int keycode) {
if (keycode == Keys.BACK || keycode == Keys.ESCAPE) {
dialog.setVisible(true);
}
return false;
}
这是我在对话框中的按钮:
btnNo.addListener(
new ClickListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
{
return true;
}
public void touchUp(InputEvent event, float x, float y, int pointer, int button){
dialog.setVisible(false);
}
});
如果你有任何想法,请告诉我。。。
查看以下网站,他们对如何在LibGDX中使用Dialog有明确的描述http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/Dialog.html
Render()中的以下块代码解决了我的问题:
if (Gdx.input.isKeyPressed(Keys.BACK) || Gdx.input.isKeyPressed(Keys.ESCAPE)){
Gdx.input.setCatchBackKey(true);
dialog.setVisible(true);
}