Add Actions.scaleTo() to a Label in LibGDX

不羁的心 提交于 2019-11-28 13:00:58

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

For more detail you can check
https://github.com/libgdx/libgdx/wiki/Scene2d.ui#rotation-and-scale

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

Labels don't directly support scaling. The easy way to solve this is put the label in a Container, setTransform(true) on the Container, and add your scale action to the Container.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!