我使用libgdx进行简单的乒乓球游戏,并且在按下后退按钮时我试图显示对话框。 我的活动实现了Screen,InputProcessor,到目前为止我在keyDown方法中编写了这个:
@Override
public boolean keyDown(int keycode) {
if (Gdx.input.isKeyPressed(Input.Keys.BACK )) {
final Dialog diag = new Dialog("Pause", skin);
TextButton Ok = new TextButton(" Ok ", skin);
TextButton Annulla = new TextButton(" Annulla ", skin);
diag.getButtonTable().add(Ok).row();
diag.getButtonTable().add(Annulla);
diag.show(stage);
stage.addActor(diag);
}
return false;
}
在渲染方法中我有:
@Override
public void render(float delta) {
Gdx.input.setInputProcessor(stage);
update(delta);
draw(delta);
}
更新(delta)更新球和桨。 draw(delta)在屏幕上绘制得分。
我的问题是对话框永远不会出现。
编辑:
private void draw(float dt) {
Gdx.gl.glClearColor(R / 255.0f, G / 255.0f, B / 255.0f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act();
stage.draw();
batch.begin();
String text = "SCORE 1: " + score1 + " SCORE 2: " + score2;
font.draw(batch, text, (Gdx.graphics.getWidth() - font.getBounds(text).width )/2, Gdx.graphics.getHeight() - font.getBounds(text).height);
String text2 = "Velocity: " + Math.sqrt((ball.getVelocityX() * ball.getVelocityX() )+ (ball.getVelocityY() * ball.getVelocityY() ));
font.draw(batch, text2 , (Gdx.graphics.getWidth() - font.getBounds(text2).width )/2, Gdx.graphics.getHeight() - (font.getBounds(text2).height + font.getBounds(text).height));
batch.end();
drawBall(dt);
drawPaddles(dt);
}