Libgdx:单击ImageButton更改图像

4
在我的Libgdx游戏中,我希望在单击ImageButton时更改图像。 我认为这应该很容易,但我已经花费了好几个小时。 :)
    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"));

        }
    }

这个不起作用。有人能帮我解决一下吗?

谢谢

1个回答

15

我通过设置checked图片解决了我的问题。

ImageButton (Drawable imageUp, Drawable imageDown, Drawable imageChecked)

然后

    if (gameData.isSound())
        buttonSound.setChecked(false);
    else
        buttonSound.setChecked(true);

4
我非常欣赏当人们回到他们的问题并发布他们找到的答案。 - Achraf Amil

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接