問題描述
在 LibGDX 中,我想為我的游戲制作文本動畫.因此,我希望我的標(biāo)簽隨著時間的推移而變大.但是如果我使用 scaleTo()
方法,什么都不會發(fā)生,而像 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);
如何讓我的標(biāo)簽按比例縮放?提前謝謝!
How can I make my labels scale? Thank you in advance!
推薦答案
出于性能原因,大多數(shù)scene2d.ui組默認(rèn)將transform設(shè)置為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 來設(shè)置單個小部件的大小和對齊方式.
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();
}
在容器而不是標(biāo)簽上添加您的操作.
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)));
這篇關(guān)于將 Actions.scaleTo() 添加到 LibGDX 中的標(biāo)簽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!