Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 407
user8340536 Avatar asked Aug 10 '17 07:08

user8340536


1 Answers

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);
like image 141
Abhishek Aryan Avatar answered Oct 19 '22 09:10

Abhishek Aryan