【发布时间】:2016-01-07 06:37:33
【问题描述】:
我正在尝试在当前阶段之上实现 HUD 阶段。我能够渲染和绘制 HUD 舞台,但其按钮的触摸事件没有响应。
我从 GameScreen 的 draw() 方法调用我的 drawHUD()。 drawHUD() 的代码是
public void drawHud(int scoreVal){
Hud.this.getCamera().update();
Hud.this.hudSpriteBatch.setProjectionMatrix(Hud.this.getCamera().combined);
hudSpriteBatch.begin();
scoreStr = "Score: " + scoreVal;
glyphLayout.setText(scoreFont, scoreStr);
halfWidth = glyphLayout.width/2;
halfHeight = glyphLayout.height/2;
scoreFont.draw(hudSpriteBatch, scoreStr, EatGame.CAMERA_WIDTH/2 - halfWidth, EatGame.CAMERA_HEIGHT - halfHeight);
hudSpriteBatch.end();
}
我在创建 HUD 时像这样向我的 pauseBtn 添加了一个监听器
pauseBtn.addListener(new InputListener() {
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
System.out.println("PauseBtn Touched");
return false;
}
}
我也通过设置按钮的边界进行了测试,但它没有响应事件。 感谢您的阅读和帮助。
【问题讨论】:
-
touchDown 必须返回一个布尔值。这可以编译吗?
-
现在已编辑,我正在尝试删除一些代码。
标签: libgdx touch imagebutton hud