Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGDX ImageButton image not to scale?

screenshot of image

The red square is the button's boundary, while the image remains centered at 32x32px. I've tried using button.getImage() to set position and size to the button's values, but it doesn't seem to have any effect.

like image 466
oracleCreeper Avatar asked Mar 20 '23 05:03

oracleCreeper


2 Answers

Just use a regular Button. It also contains a Drawable for its background, but that one is always stretched to fill the button. See the JavaDoc for ImageButton:

... If the image is the size of the button, a Button without any children can be used, where the Button.ButtonStyle.up, Button.ButtonStyle.down, and Button.ButtonStyle.checked nine patches define the image.

Note that these don't actually need to be nine patches; any Drawable will do.

like image 140
Thomas Avatar answered Apr 01 '23 13:04

Thomas


Probably super late but have you tried:

yourButton.getImage().setFillParent(true);
like image 23
xitnesscomplex Avatar answered Apr 01 '23 12:04

xitnesscomplex