如何在 LibGdx 中缩放标签

How do i scale a Label in LibGdx(如何在 LibGdx 中缩放标签)

本文介绍了如何在 LibGdx 中缩放标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的游戏编写 HUD,但我不知道如何正确缩放标签我正在使用此代码:

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 

HP 标签在屏幕上很大.我尝试在标签和桌子上使用 setScale 无济于事.任何帮助表示赞赏!谢谢

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

这是当前屏幕的图片https://gyazo.com/57c190a9d7516bb8b2256bf1a7d17b4c

推荐答案

只需将标签添加到组,然后将比例应用于组.

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);

我只在动画中缩放带有标签的组,在动画结束时缩放为 1.不应缩放字体,因为它看起来像素化.比如一个简单的放大缩小动画:

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)));

这篇关于如何在 LibGdx 中缩放标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 LibGdx 中缩放标签

基础教程推荐