将 Actions.scaleTo() 添加到 LibGDX 中的标签

Add Actions.scaleTo() to a Label in LibGDX(将 Actions.scaleTo() 添加到 LibGDX 中的标签)
本文介绍了将 Actions.scaleTo() 添加到 LibGDX 中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在 LibGDX 中,我想为我的游戏制作文本动画.因此,我希望我的标签随着时间的推移而变大.但是如果我使用 scaleTo() 方法,什么都不会发生,而像 moveTo() 这样的其他动作可以正常工作.

In LibGDX, I want to make a text animation for my game. Therefore, I want that my labels gets larger with time. But if I use the scaleTo() method, nothing happens whereas other Actions like moveTo() work fine.

label1 = new Label("Test text", new Label.LabelStyle(font, Color.BLACK));
label2.addAction(Actions.parallel(Actions.moveTo(500, 300, 2.0f),Actions.scaleTo(0.1f, 0.1f,2.0f)));

label2 = new Label("Test text 2", new Label.LabelStyle(font, Color.BLACK));
label2.addAction(Actions.parallel(Actions.moveTo(500, 300, 2.0f),Actions.scaleTo(0.1f, 0.1f,2.0f)));

stage.addActor(label1);
stage.addActor(label2);

如何让我的标签按比例缩放?提前谢谢!

How can I make my labels scale? Thank you in advance!

推荐答案

出于性能原因,大多数scene2d.ui组默认将transform设置为false.

For performance reason most scene2d.ui groups have transform set to false by default.

更多详情请查看
https://github.com/libgdx/libgdx/wiki/Scene2d.ui#rotation-and-scale

如果你想缩放,你可以使用 Container 来设置单个小部件的大小和对齐方式.

If you want to scale, you can use Container which is useful for setting the size and alignment of a single widget.

private Container<Label> container;

@Override
public void create() {
    stage=new Stage();

    Label label1 = new Label("Test text", new Label.LabelStyle(font, Color.BLACK));

    container=new Container<Label>(label1);
    container.setTransform(true);   // for enabling scaling and rotation
    container.size(100, 60);
    container.setOrigin(container.getWidth() / 2, container.getHeight() / 2);
    container.setPosition(100,200);
    container.setScale(3);  //scale according to your requirement

    stage.addActor(container);
}

@Override
public void render() {
    super.render();

    Gdx.gl.glClearColor(1,1,1,1);
    gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    stage.draw();
    stage.act();
}

在容器而不是标签上添加您的操作.

Add your Action on container instead of Label.

container.addAction(Actions.parallel(Actions.moveTo(500, 300, 2.0f),Actions.scaleTo(0.1f, 0.1f,2.0f)));

这篇关于将 Actions.scaleTo() 添加到 LibGDX 中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)