Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

LibGDX: Skin and scaling problems

$
0
0

I’m trying to use Skins with TextButtons. However I’m having an issue where the TextureRegions of the Skin are NOT being scaled down to the tablesize.

This is leading to an issue like in this image:

enter image description here

As you can see that is the e from the word Hello. I managed to scale that down to a more reasonable size (still wrong). However the Button textures are still way too large.

enter image description here

Any ideas? Because I am pulling my hair out. I am using a custom viewport with a custom screenspace width and height. Here is the create method for the menu.

    public void create(){
    menuStage = new Stage();
    camera = new OrthographicCamera();
    viewPort = new StretchViewport(SCREEN_SPACE_WIDTH, SCREEN_SPACE_HEIGHT, camera);
    viewPort.setWorldSize(SCREEN_SPACE_WIDTH, SCREEN_SPACE_HEIGHT);
    menuStage.setViewport(viewPort);

    devTexture = new Sprite (new Texture(Gdx.files.internal("data/16by9.png"), true));


    Image newActor = new Image(devTexture.getTexture());
    newActor.setSize(
            viewPort.getWorldWidth(),
            viewPort.getWorldHeight()
    );

    menuStage.addActor(newActor);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));

    menuTable = new Table();

    skin.getFont("default-font").setScale(0.08f);

    menuTable.debugAll();

    menuTable.setFillParent(true);
    TextButton a,b,c;

    a = new TextButton("hello", skin);
    b = new TextButton("hello", skin);
    c = new TextButton("hello", skin);

    a.getStyle().up.setMinWidth(2.0f);

    b.getStyle().up.setMinHeight(2.0f);
    b.getStyle().up.setMinWidth(2.0f);

    c.getStyle().up.setMinHeight(2.0f);
    c.getStyle().up.setMinWidth(2.0f);

    menuTable.row();
    menuTable.add(a).size(2.0f, 1.0f);
    menuTable.add(b).size(2.0f, 1.0f);
    menuTable.add(c).size(2.0f, 1.0f);

    menuStage.addActor(menuTable);

    camera.translate(
            newActor.getWidth() / 2,
            newActor.getHeight() / 2
    );
}

Viewing all articles
Browse latest Browse all 434

Trending Articles