2

如果您不弄乱旋转,则相对于另一个精灵对象定位精灵对象非常容易。正如标题所述,我想知道如何相对于已经旋转的 MC 定位 2 MC,因此它们彼此对齐。大火箭呈35度角。

首先,我将大火箭的角度设置为 0 度,我在舞台上添加 2 个小火箭,并将它们放置在大火箭的每一侧。到目前为止一切顺利...我将所有内容旋转回初始角度(35 度),但有些地方不对劲,您可以在 pic1 中看到结果

我必须改变什么,以使 2 个小火箭保持完全对齐(一个在左侧,另一个在较大火箭的右侧)并旋转,如图 2 所示?

所有对象的注册点都在左上角。

编辑:2 个小火箭必须位于较大的火箭容器之外,因为最终它们将独立于容器进行动画处理。

1 图2

var _rot = rocketShip.rotation;
rocketShip.rotation = 0;
addChild(_leftRocket);
addChild(_rightRocket);
_leftRocket.x = rocketShip.x - _leftRocket.width;
_leftRocket.y = rocketShip.y + 20;
_rightRocket.y = rocketShip.x + _rightRocket.width;
_rightRocket.y = rocketShip.y + 20;
rocketShip.rotation = _rot;
_leftRocket.rotation = _rightRocket.rotation = rocketShip.rotation;
4

1 回答 1

0

尝试旋转后将_leftRocket和_rightRocket移动到正确的位置。

这是代码移动_leftRocket

//the old left bottom point of rocketShip
var point1:Point= new Point(0, rocketShip.height);

//the old right-bottom poiny of leftship
var point2:Point = new point(_leftRocket.width, _leftRocket.height);

//the old right bottom point of rocketShip
var point5:Point= new Point(rocketShip.width, rocketShip.height);

//the old left-bottom point of rightship's 
var point6:Point = new point(0, _leftRocket.height);

//.. Your code


//get the new position of rocketship's left bottom point after rotation,leftShip's right bottom corner will be in this point
var point3:Point =  rocketShip.transform.matrix.transformPoint(point1);

//get the new  point of leftship's right-bottom-corner after rotation.
var point4:Point =  _leftRocket.transform.matrix.transformPoint(point2);

//move the leftShip
_leftRocket.x -= point4.x - point3.x;
_leftRocket.y -= point4.y - point3.y;

在这里寻找合适的船

//get the new position of right bottom point  of rocketShip after rotation,rightShip's left bottom corner will be in this point
var point7:Point =  rocketShip.transform.matrix.transformPoint(point5);

//get the new  point of rightship's left-bottom-corner after rotation.
var point8:Point =  _rightRocket.transform.matrix.transformPoint(point6);

//move the rightShip
_rightRocket.x -= point8.x - point7.x;
_rightRocket.y -= point8.y - point7.y;

我认为你应该改变

 _rightRocket.y = rocketShip.x + _rightRocket.width;

 _rightRocket.x = rocketShip.x + rocketShip.width;
于 2013-06-28T17:13:28.637 回答