2013-07-26 129 views
3

我有一個TEXT按鈕,我想將它通過90度旋轉的屏幕上。旋轉TEXT按鈕與libgdx

出於某種原因,旋轉的所有方法(旋轉(),setRotationAngle()等)與TEXT按鈕對象的產生密切相關不正常工作。

所以我實現了新的類擴展TEXT按鈕和壓倒一切的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度,但是對於某些未知的度數。

enter image description here

UPD

後,我切換回TEXT按鈕對象,做:

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

它幾乎工作意味着在按鈕中的文本被corrently旋轉,但背景留在它的按鈕現貨:

enter image description here

所以我的問題是:爲什麼會出現這種情況,我該如何解決這個問題?

回答

3

我實現了旋轉小工具根據documentation

這裏是我的代碼:

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

然後:

rotatingActor.setRotation(newDegree); 

所有的點擊處理程序等方面的工作,因爲即使預期如果小部件旋轉。

1

上現有的參與者旋轉方法應該工作。可能值得提出另一個問題來追蹤這個問題。

我看到至少有兩個問題:

  1. 缺省的批處理transorm矩陣可能不是單位矩陣。也許初始化rotationMatrix作爲oldMatrix的副本?

  2. 你正在圍繞一個真正的任意向量旋轉(從原點 - 從左下角到左上角繪製一條線)。嘗試Vector3(0, 1, 0)

+0

旋轉與其他載體沒有幫助。但TextButton對象的方法setTrasform()幫助旋轉按鈕的文本,但不是按鈕本身(P.S我已更新問題) –

2

有一個project issue關閉,因爲不會修復。

由於剪切是通過剪切實現的,因此無法旋轉scene2d中的所有UI元素。剪刀需要軸對齊的矩形。

+0

好吧,但這並不意味着無法通過矩陣轉換實現旋轉。 –