Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i scale a Label in LibGdx

i am trying to code a HUD for my game but i cannot figure out how to scale a Label properly I am using this code:

Label hpLabel = new Label("HP: ",new Label.LabelStyle(new BitmapFont(),Color.BROWN));
    table.add(hpLabel);
    viewport = new FitViewport(Gdx.graphics.getWidth()/ FacultyWars.PPM, Gdx.graphics.getHeight()/ FacultyWars.PPM, cam);
    stage = new Stage(viewport, batch);
    stage.addActor(table);
//other ellements added after this 

The HP tag is enormous on the screen. I tried using setScale on the label and on the table to no avail. Any help is appreciated! Thanks

Here is a picture of the current screen https://gyazo.com/57c190a9d7516bb8b2256bf1a7d17b4c

like image 573
Adrien Pecher Avatar asked Jan 04 '23 08:01

Adrien Pecher


2 Answers

Simply add the Label to a Group then apply the scale to the group.

    Label label = new Label("hello", skin);
    Group group = new Group();
    group.addActor(label);
    group.setScale(2f, 2f);

I only scale Groups with Labels in animations where at the end of the animation the scale is 1. One should not scale fonts, because it looks pixelated. For example, a simple scale up scale down animation:

group.addAction(Actions.sequence(Actions.scaleTo(2f, 2f, 1f), Actions.scaleTo(1f, 1f, 1f)));
like image 51
Mira Stinktshir Avatar answered Jan 06 '23 22:01

Mira Stinktshir


Use setFontScale(float fontScale) method of Label

like image 37
Draz Avatar answered Jan 06 '23 23:01

Draz