Abd*_*doe 4 java button mousepress libgdx
为什么我的TextButtonlibgdx没有响应点击?
我有一个按钮,这个按钮有一个监听器,但它没有响应.该按钮正在显示,但它不会响应鼠标点击.
public MyStage extends Stage {
...
next.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
{
Gdx.app.log(ApothecaryGame.LOG, "Pressed: Next button.");
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log( ApothecaryGame.LOG, "Released: Next button.");
super.touchUp( event, x, y, pointer, button );
nextPage();
}
} );
this.addActor(next);
}
Run Code Online (Sandbox Code Playgroud)
Rod*_*yde 15
将ClickListener添加到按钮.它看起来像这样.
button.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
// Do something interesting here...
}
});
Run Code Online (Sandbox Code Playgroud)
此外,请确保将舞台设置为输入处理器,否则将无法看到事件.
Gdx.input.setInputProcessor(stage);
Run Code Online (Sandbox Code Playgroud)