如何在ActionScript 3获得视觉的角落(例如左上)旋转displayObject的吗?
-
19-09-2019 - |
题
当旋转显示对象(围绕其中心)的移动元件的视觉角(以下简称“盒”的实际x和y保持不变)。例如具有45度的旋转的X坐标将增加和y坐标将已减少的左上角是现在的“盒子”中上。
我试图使用displayObject.getBounds(coordinateSpace).topLeft然而此方法简单地返回框的x和y,从而一个对象已经旋转后不会改变。
那么,你如何得到的x和y一视觉旋转的显示对象的角落?
更新:这是我的意思是用旋转后视觉角落的位置 - > 替代文字http://feedpostal.com/cornerExample.gif
解决方案
您只需要翻译点其父的坐标空间。
var box:Shape = new Shape();
box.graphics.beginFill(0xff0099);
box.graphics.drawRect(-50, -50, 100, 100); // ... the center of the rectangle being at the middle of the Shape
addChild(box);
box.x = 100; // note: should be 100 + box.width * .5 in case you want to use the topleft corner to position
box.y = 100;
box.rotation = 45;
// traces the result (Point)
trace( box.parent.globalToLocal(box.localToGlobal(box.getBounds(box).topLeft)) );
不隶属于 StackOverflow