据我了解,LibGDX
中的ImageButton
是一个包含图像的框架。是否可以设置框架的背景?
例如,我想使用按钮背景,并在该图像上应用图标。
当前代码
皮肤与背景:
"com.badlogic.gdx.scenes.scene2d.ui.ImageButton$ImageButtonStyle": {
"default": {
"imageDown": "button-down",
"imageUp": "button-up"
}
}
创建图像按钮:
// Getting imageButtonStyle with "default" style, as it just has the background.
ImageButton.ImageButtonStyle imageButtonStyle = skin.get( "default", ImageButton.ImageButtonStyle.class );
ImageButton button = new ImageButton( imageButtonStyle );
// Set the image on the button to something.
背景图片。
覆盖图标的背景图片。
感谢您的帮助。
最佳答案
诀窍是使用 2 种不同的可用样式。 ImageButtonStyle 来设置图标属性,但是由于ImageButtonStyle 扩展了ButtonStyle,所以背景属性在ButtonStyle 中设置。像这样的东西:
ImageButtonStyle style = new ImageButtonStyle();
style.up = background;
style.down = background;
style.checked = background;
style.imageUp = icon_up;
style.imageDown = icon_down;
style.imageChecked = icon_checked;
style.unpressedOffsetY = -20; // to "not" center the icon
style.unpressedOffsetX = -30; // to "not" center the icon
ImageButton heartButton = new ImageButton(style);
ImageButton envelopeButton = new ImageButton(envelopeStyle);
类似的东西(对我来说,背景,icon_* 是可绘制的)。但这是最基本的,对我来说就像一个魅力。
关于android - LibGDX - ImageButton - 设置图像背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26429723/