【发布时间】:2013-07-26 09:56:01
【问题描述】:
我有一个 textButton,我想把它放在旋转 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 度,而是旋转了一些未知的度数。
UPD
在我切换回 TextButton 对象并做了之后:
newGame.setTransform(true);
newGame.rotate(90);
这意味着按钮中的文本已正确旋转,但按钮的背景保持在原位:
所以我的问题是:为什么会发生这种情况,我该如何解决?
【问题讨论】:
标签: android libgdx matrix-transform