按钮不会旋转libGDX

时间:2017-08-10 07:22:06

标签: java android button libgdx rotation

我想旋转一个按钮。因此我写了以下代码:

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

不幸的是,按钮没有旋转,但我不知道为什么。 如何改进我的代码?

1 个答案:

答案 0 :(得分:6)

出于性能原因,默认情况下,大多数scene2d.uitransform设置为false。

有关详细信息,请查看
https://github.com/libgdx/libgdx/wiki/Scene2d.ui#rotation-and-scale

您需要使用setTransform(..)方法

启用转换
button2.setTransform(true);