In my game in Libgdx I want to change ImageButton image on click. I think this should be easy, but I have lost hours on this. :)
public void show() {
buttonSound = new ImageButton(skin.getDrawable("sound_off"));
buttonSound.addListener(new onSoundListener());
}
class onSoundListener extends InputListener {
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
return true;
}
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
buttonSound.setBackground(skin.getDrawable("btn_sound"));
}
}
This doesn't work. Can someone help me with this?
Thanks
I found solution for my problem by setting checked
image
ImageButton (Drawable imageUp, Drawable imageDown, Drawable imageChecked)
and then
if (gameData.isSound())
buttonSound.setChecked(false);
else
buttonSound.setChecked(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With