2012-11-25 23 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