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 中缩放标签
基础教程推荐
- Struts2 URL 无法访问 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
