How do i scale a Label in 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 中缩放标签


- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 转换 ldap 日期 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 获取数字的最后一位 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01