Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scene2d button scaling with libgdx

I don't know if it is just me, but drawables confuse me. Are they intended to keep the size they are given, or is there a way to scale the image within them? I understand they can use ninepatch to fill certain areas by stretching an image, but I want to scale the image that it stretches. I am using a TextButton for my menu buttons, but they are way too big, and I would love to know how to scale them. I am retrieving the skin from an atlas, which has ninepatch images in it. Here is the settings screen: The settings screen Here are the images in the pack I am using: ninepatch images packed Here is the initialization of the TextureAtlas, and Skin:

buttonAtlas = new TextureAtlas(Gdx.files.internal("buttons/buttons.pack"));
buttonSkin = new Skin(buttonAtlas); 

Here is the initialization of that menu button.

TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.up = Assets.buttonSkin.getDrawable("bluebutton");
textButtonStyle.down = Assets.buttonSkin.getDrawable("redbutton");
textButtonStyle.font = font;

buttonMenu = new TextButton("Menu", textButtonStyle);
buttonMenu.pad(20.0f);
buttonMenu.addListener(new ClickListener() {
    @Override
    public void clicked(InputEvent event, float x, float y) {
        game.fade.startFadeOut();
        super.clicked(event, x, y);
    }
});

And perhaps I could change how I put it in the table, or how I put the table in the stage?

table.add(buttonMenu).width(Gdx.graphics.getWidth()/4);
stage.addActor(table);

As a last resort I suppose I could attempt creating my own text button actor that I could scale, thank you for your time.

like image 257
Austin Gibb Avatar asked May 11 '14 15:05

Austin Gibb


1 Answers

First of all if you know that your images are too big: The best would be to scale the images themselves to a smaller size and then use the TexturePacker too generate a new TextureAtlas that contain the smaller images.

Anyhow you can scale the image button with the TableLayout if you really want to, see example:

table.add(buttonMenu).width(100).height(100);
like image 60
donfuxx Avatar answered Nov 14 '22 12:11

donfuxx