DreamsInHD
DreamsInHD

Reputation: 413

libgdx buttons in table stretching

I want to create buttons in the corners of the screen for the controls of my game. It used to work with just creating a skin, adding that skin to a new ImageButton(skin) and setting the size and position of that button to what is desired. I now use box2d and if i now set the size of the button to (1, 1) the height is correct but the width is always about 2/3 of the screen, no matter what i change it to. I tried using a table and doing this:

    table = new Table();
    table.setFillParent(true);
    stage.addActor(table);
    table.setDebug(true);
    table.add(boostButtonn).width(1).height(1).bottom().right();

But I have no clue how to draw it in the corner of the screen, also the button is drawn in the middle of the screen with the correct size using this table, but the skin is stretched out of the button. Viewport width and height are 40,24 respectively

My skin and button code:

Skin skin = new Skin(Gdx.files.internal("skin/flath-earth-ui.json"));
Button bootsButton = new ImageButton(skin);

And then i add it to the table

Upvotes: 0

Views: 616

Answers (1)

AAryan
AAryan

Reputation: 20140

Problem is not in how you align or arrange your widget. Problem is why button/widget or even text is stretched and looks blurry.

Why stretched ?

Problem is in your resources. Your resources should be compatible with your viewport. If you're using small viewport then we need your resources(images and fonts) in small size.

You're using skin, that used to create Widget. Skin depends on .json file that contains information about your Widget object and .atlas files having information of your image file.

You're using 40 as width of viewport then button image that used as drawable should be in range of approx. 10.

So what is solution now :

If you already have all resources ready then use some higher viewport dimension according to your resources else create create resources according to viewport.

Upvotes: 0

Related Questions