如何使ImageButton在libgdx中看起来按下?

时间:2019-04-17 16:08:25

标签: libgdx

我在游戏中使用了 ImageButton ,我想让它显示被触摸或按下。 libgdx 框架是我的新手。

TextureRegion btLeft = new TextureRegion(new Texture("NUMBEROFF.png"));
        Drawable drawableLeft = new TextureRegionDrawable(new TextureRegion(btLeft));
        buttonLeft = new ImageButton(drawableLeft);

1 个答案:

答案 0 :(得分:0)

ImageButton有不同的构造函数,可让您在按钮处于不同状态(上,下和选中)时添加多个Drawable。但是我更喜欢使用ImageButtonStyle来做到这一点。

https://libgdx.badlogicgames.com/ci/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ImageButton.ImageButtonStyle.html

ImageButtonStyle style = new ImageButtonStyle();
style.imageUp = ...your drawable for up (normal) state
style.imageChecked = ...your drawable for checked state
style.imageDown = ...your drawable for down (pressed) state

ImageButton button = new ImageButton(style);