按钮不会旋转libGDX [英] Button doesn´t rotate libGDX
本文介绍了按钮不会旋转libGDX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想旋转一个按钮.因此,我编写了以下代码:
I want to rotate a button. Therefore I wrote the following code:
public void show () {
skin2 = new Skin (Gdx.files.internal("SettingsButton.json"));
button2 = new Button(skin2);
button2.setPosition(25,1440);
button2.setSize(120,120);
button2.setOrigin(button2.getWidth() / 2, button2.getHeight() / 2);
button2.addAction(Actions.repeat(RepeatAction.FOREVER,
Actions.sequence(
Actions.rotateBy(360, 1),
Actions.rotateTo(0))));
button2.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y) {
game.setScreen(new SettingsScreen(game));
super.clicked(event, x, y);
}
});
stage.addActor(button2);
}
不幸的是,按钮没有旋转,但我不知道为什么. 如何改进我的代码?
Unfortunately, the button doesn´t rotate but I don´t know why. How can I improve my code?
推荐答案
出于性能原因,大多数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
For more detail you can check
https://github.com/libgdx/libgdx/wiki/Scene2d.ui#rotation-and-scale
您需要使用setTransform(..)
方法启用转换
You need to enable transform by using setTransform(..)
method
button2.setTransform(true);
这篇关于按钮不会旋转libGDX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文