我有一个文本按钮,想把它旋转90度放在屏幕上。
不知何故,所有与TextButton对象相关的旋转方法(rotate()、setRotationAngle()等)都无法正常工作。
因此,我实现了一个扩展TextButton类并覆盖draw()方法的新类:
@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);
}
当rotationAngle
等于90.0时。但由于某种原因,按钮没有旋转90度,而是以未知的角度旋转。
更新
在我切换回对象并执行以下操作后:
newGame.setTransform(true);
newGame.rotate(90);
几乎成功了,这意味着按钮中的文本已正确旋转,但是按钮的背景仍然停留在原地:
![enter image description here](https://istack.dev59.com/UaYo1.webp)