Button doesn´t rotate libGDX

2019-07-09 11:50发布

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?

1条回答
甜甜的少女心
2楼-- · 2019-07-09 12:16

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

You need to enable transform by using setTransform(..) method

button2.setTransform(true);
查看更多
登录 后发表回答