其中a, d 影响显示对象的缩放, c, d 影响显示对象的倾斜, a, b, c, d同时影响显示对象的旋转。 tx, ty 代表显示对象相对于父对象的位置偏移!如果 都为0 的话,
那么就是 所以说, tx, ty 就是显示对象的坐标。
四、应用
1. 获取对象里某一点在父对象中的位置。
var p:Point = new Point( x0, y0 );
p = displayObject.transform.matrix.transformPoint( p );
2. 绘制渐变图
代码示例略
3. 中心旋转
public function rotateAroundCenter (ob:DisplayObject, angleDegrees:Number):void
{
var matrix:Matrix = ob.transform.matrix;
var rect:Rectangle = ob.getBounds(ob.parent);
matrix.translate(- (rect.left + (rect.width/2)), - (rect.top + (rect.height/2)));
matrix.rotate((angleDegrees/180)*Math.PI);
matrix.translate(rect.left + (rect.width / 2), rect.top + (rect.height / 2));
ob.transform.matrix = matrix;
}
4. 绕点旋转
// get matrix object from your MovieClip (mc)
var m:Matrix = mc.transform.matrix;
// set the point around which you want to rotate your MovieClip (relative to the MovieClip position)
var point:Point = new Point(10, 10);
// get the position of the MovieClip related to its origin and the point around which it needs to be rotated
point = m.transformPoint(point);
// set it
m.translate( -point.x, -point.y);
// rotate it of 30°
m.rotate(30 * (Math.PI / 180));
// and get back to its "normal" position
m.translate(point.x, point.y);
// finally, to set the MovieClip position, use this
mc.transform.matrix = m;
// or this
mc.x = m.tx;
mc.y = m.ty;
mc.rotation += 30;