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.
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:
So my question is: Why does this happen and how can I solve this ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With