1
\$\begingroup\$

How to keep rotating a button on main menu screen around its center, here's the code for the button

final ImageButton btnSett=UIFactory.createButton(txtrSettings);
btnSett.setScale(1,1);
btnSett.setPosition(Gdx.graphics.getWidth()/ 2,0.f, Align.center);
stage.addActor(btnSett);
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Try applying an Action to the button.

For example, to make the Button rotate once apply a rotate action:

btnSett.addAction(Actions.rotateBy(360, 1));

This will rotate btnSett once over one second. To make something continuously rotate you can apply a repeated action, and actions can also be in sequence, for example;

btnSett.addAction(Actions.repeat(RepeatActions.FOREVER, 
                  Actions.sequence(
                     Actions.rotateBy(360, 1), // First, rotate once   
                     Actions.rotateTo(0));     // Then, instantly set the rotation to 0 so that the previous action makes sense again.

You'll also need to set the origin of the Button to it's center first;

btnSett.setOrigin(btnSett.getWidth() / 2, btnSett.getHeight() / 2);

To make the actions code look cleaner consider making static imports of the methods in Actions, that way the code can look more like;

btnSett.addAction(repeat(RepeatActions.FOREVER, 
                         sequence(rotateBy(360, 1), 
                                  rotateTo(0));     
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .