user8340536
user8340536

Reputation: 209

Button doesn´t rotate 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?

Upvotes: 5

Views: 510

Answers (1)

AAryan
AAryan

Reputation: 20140

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

Upvotes: 12

Related Questions