AS3中,使用DisplayObject的transform/matrix,需要先clone出来,再变换,再赋值回去,这样才会对DisplayObject产生影响,不能直接对原Matrix操作。
详细见下边的代码:
var a:Sprite = new Sprite();a.graphics.beginFill(0);a.graphics.drawRect(0,0,100,100);a.graphics.endFill();a.x = a.y = 10;addChild(a);trace (a.transform.matrix ); var m:Matrix = a.transform.matrix .clone();m.translate(30,30);a.transform.matrix = m;trace (a.x, a.y);trace (a.transform.matrix ); m.translate(30,30);a.transform.matrix = m; //只有赋值Matrix的时候,才会有反应trace (a.x, a.y);trace (a.transform.matrix); a.transform.matrix .translate(30,30); //这里不会有任何效果,不会对a产生影响trace (a.x, a.y);trace (a.transform.matrix );
输出:
(a=1, b=0, c=0, d=1, tx=10, ty=10)
40 40
(a=1, b=0, c=0, d=1, tx=40, ty=40)
70 70
(a=1, b=0, c=0, d=1, tx=70, ty=70)
70 70
(a=1, b=0, c=0, d=1, tx=70, ty=70)