如果不弄乱旋转,很容易将精灵对象相对于另一个精灵对象定位。正如标题所述,我想知道如何将2 MC相对于已经旋转的MC定位,因此它们彼此对齐。大火箭的角度为35度。
首先我将大火箭的角度设置为0度,我在舞台上添加2个小火箭,并将它们放置在较大火箭的两侧。到目前为止一切都那么好......我正在将所有东西都旋转回初始角度(35度),但有些东西是不对的,因为你可以在pic1中看到结果
我必须改变什么,以便2个小型火箭保持完全对齐(一个在左侧,另一个在较大火箭的右侧)并旋转,如图2所示?
所有对象的注册点位于左上角。
编辑: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;
答案 0 :(得分:0)
尝试在旋转后将_leftRocket和_rightRocket移动到正确的位置。
这是代码move _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;