沿着中心旋转swf

时间:2014-03-25 13:39:37

标签: actionscript-3 flex flex4.5

我有一个swf,看起来像下面的图像 enter image description here

目标: - 根据给定图像,沿着中心旋转红色线swf enter image description here

我有像

这样的条件
  

x轴,y轴,x = 1,x = y,x = -y

我的前两个条件显示在图像中。 对于接下来的三个条件,图像是 enter image description here enter image description here enter image description here

1 个答案:

答案 0 :(得分:3)

您可以通过矩阵平移和旋转,或通过查找对象居中,旋转对象,然后将其平移(这与矩阵技术基本相同)来完成此操作。

矩阵方式:

var mat:Matrix = spr.transform.matrix;
var bounds:Rectangle = spr.getBounds( spr.parent );
mat.translate( -(bounds.left + bounds.width/2), -(bounds.top + bounds.height/2 ) );
mat.rotate( degree * Math.PI / 180 ); //rotate amount
mat.translate( bounds.left + bounds.width/2, bounds.top + bounds.height/2 );
spr.transform.matrix = mat;

没有矩阵:

var bounds:Rectangle = spr.getBounds( spr.parent );
var center:Point = new Point( bounds.x + bounds.width/2, bounds.y + bounds.height/2 );

spr.rotation = degree; //rotate amount

bounds = spr.getBounds( spr.parent );
var newCenter:Point = new Point( bounds.x + bounds.width/2, bounds.y + bounds.height/2 );
spr.x += center.x - newCenter.x;
spr.y += center.y - newCenter.y;