2012-11-25 24 views
1

似乎將矩陣rotate()應用於顯示對象與DisplayObject.rotation不同。我想要的是使用matrix.rotate()獲得使用rect.rotation = 45的相同結果。但實際結果是不一樣的。actionscript矩陣rotate()和DisplayObject.rotation屬性

代碼示例:

public class Demo extends Sprite { 
    public function Demo() { 
     testRotation(); 
    } 

    private function testRotation():void { 
     var rect:Shape = new Shape(); 
     rect.graphics.beginFill(0xff0000,1); 
     rect.graphics.beginFill(0xff0000, 1); 
     rect.graphics.drawRect(0,0,100,100); 
     rect.graphics.endFill(); 
     rect.x = 100; 
     rect.y = 100; 
     addChild(rect); 
     var matrix:Matrix = new Matrix(); 
     trace(matrix); 
     matrix.rotate(Math.PI*45/180); 
     rect.transform.matrix = matrix; 
    } 
} 
+1

你需要解釋什麼是 「不工作」。你想要什麼效果?你有什麼?我也不認爲這個問題與Flex框架有什麼關係,所以我不確定這個標籤是否合適。 – JeffryHouser

+0

@ www.Flextras.com,我已經重述了我的問題,謝謝你的建議 – jason

回答

0

的原因是旋轉方法繞左上角(0,0)爲PIC節目協調。 enter image description here

解決方案:

var matrix:Matrix = new Matrix(); 
matrix.translate(-50,-50)// Translate to center of square 
matrix.rotate(Math*45/180); //rotate 45 degrees 
matrix.translate(rect.x+150, rect.y+150) 
rect.transform.matrix = matrix