Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate TextButton with libgdx

I have a textButton and I want to place it on the screen rotated by 90deg.

For some reason all methods for rotation(rotate(), setRotationAngle() and so on) assosiated with TextButton object do not work properly.

So I've implemented new class extending the TextButton and overriding draw() method:

@Override
public void draw(SpriteBatch batch, float parentAlpha) {
     Matrix4 rotationMatrix = new Matrix4();
     Matrix4 oldMatrix = batch.getTransformMatrix();
     rotationMatrix.idt();
     rotationMatrix.rotate(new Vector3(this.getX(),this.getY()+this.getHeight(),0),rotationAngle);
     batch.setTransformMatrix(rotationMatrix);
     super.draw(batch, parentAlpha);
     batch.setTransformMatrix(oldMatrix);
}

Where rotationAngle equals to 90.0. And for some reason button isn't rotated by 90degress, but for some unknown amount of degrees.

enter image description here

UPD

After I switched back to TextButton object and did :

newGame.setTransform(true);
newGame.rotate(90);

It almost worked meaning that text in the button was rotated corrently, but the background of the button stayed on it's spot:

enter image description here

So my question is: Why does this happen and how can I solve this ?

like image 827
Ricardo Simmus Avatar asked Mar 24 '23 00:03

Ricardo Simmus


1 Answers

I implemented rotating Widgets according to the documentation

Here is my code:

Table buttonContainer = new Table(skin);
buttonContainer.setTransform(true);
buttonContainer.add(button1);
buttonContainer.row().pad(10);
buttonContainer.add(button2);
rotatingActor = buttonContainer;

and then:

rotatingActor.setRotation(newDegree);

All the click handlers etc. work as expected even if the widget are rotated.

like image 188
morpheus05 Avatar answered Mar 31 '23 13:03

morpheus05