Reputation: 187
This is my code:
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");
}
});
}
If I click on the button nothing happens. Why?
Upvotes: 1
Views: 1969
Reputation: 510
You should have stage
and add ImageButton
to this stage then setInputProcessor
to this stage and you can use only Image instead of ImageButton since you don't use imageUp, imageDown.....
you code should be like this :
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();
}
Upvotes: 1