这是我的代码:
Gdx.input.setInputProcessor(this);
bagImage = new Image(new Texture("bag.png"));
bagButton = new ImageButton(bagImage.getDrawable());
bagButton.setSize(125, 125);
bagButton.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
Gdx.app.debug("DEBUG", "clicked");
}
});
}
如果我点击按钮没有任何反应。为什么呢?
答案 0 :(得分:1)
您应该stage
并将ImageButton
添加到此阶段,然后setInputProcessor
添加到此阶段,您只能使用Image而不是ImageButton,因为您不使用imageUp,imageDown .....
你的代码应该是这样的:
Stage stage = new Stage();
Gdx.input.setInputProcessor(stage);
bagImage = new Image(new Texture("bag.png"));
bagImage.setSize(125, 125);
stage.addActor(bagImage);
bagImage.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y){
Gdx.app.debug("DEBUG", "clicked");
}
});
@Override
public void render(float delta) {
stage.act(delta);
stage.draw();
}