0

我正在开发一个绘图应用程序,我遇到了一个问题,一个可能的解决方案是能够水平调整图像的大小(增加或减少宽度)而不改变它的轴心,但以“定向调整大小”结束,这意味着,如果我开始拖动正确的调整大小锚,图像开始向右增加其宽度,而不是始终考虑枢轴。

所以,我现在正在做的是增加宽度,同时我移动图像宽度/2,它可以工作,但是当我必须旋转图像时..一切都开始损坏,即使我设置精灵中间的枢轴,因为图像(包含在精灵中)x 被改变了,所以没关系。

我读过一些关于矩阵的文章,但我不确定这是否可能。

谢谢。

4

1 回答 1

2

有几种方法可以做到这一点。第一种是使用变换矩阵。这是我用来以这种方式围绕一个点旋转对象的函数:

*您需要导入 fl.motion.MatrixTransformer,如果不使用 flashPro,您可以在此处获取: https ://code.google.com/p/artitem-as3/source/browse/trunk/ArtItem/src/fl /motion/MatrixTransformer.as?r=3

                 /**
                 * Rotates a displayObject around the passed local point.
                 * @param   displayObj
                 * @param   relativeDegrees - the relative amount of degrees to rotate the object
                 * @param   point - a local point to rotate the object around, if null, center of bounding box will be used.
                 */
                public static function rotateAroundPoint(displayObj:DisplayObject, relativeDegrees:Number, point:Point = null):void {
                    var m:Matrix  = displayObj.transform.matrix.clone();

                    if (!point) {
                        //default is center of bounding box
                        var r:Rectangle = displayObj.getBounds(displayObj);
                        point = new Point(r.x + (r.width * .5), r.y + (r.height * .5));
                    }
                    MatrixTransformer.rotateAroundInternalPoint(m, point.x, point.y, relativeDegrees);
                    displayObj.transform.matrix = m;
                }

另一种更懒惰的方法是使用虚拟父对象并旋转它:

var dummy:Sprite = new Sprite();
dummy.addChild(yourObjectToRotate);

//this effectively makes the anchor point of dummy in the center, so when you rotate it it rotate from the center.
yourObjectToRotate.x = -(yourObjectToRotate.width * .5);
yourObjectToRotate.y = -(yourObjectToRotate.height * .5);

dummy.rotation = 90;
于 2013-05-06T20:44:40.120 回答