【问题标题】:Increase width without moving image在不移动图像的情况下增加宽度
【发布时间】:2013-04-30 14:38:43
【问题描述】:

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

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

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

谢谢。

【问题讨论】:

  • 这可能是您尝试过的,但您是否尝试过改变 scaleX 而不是宽度?我不确定这是否会导致枢轴表现更好

标签: actionscript-3 matrix resize width pivot


【解决方案1】:

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

*您需要导入 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-15
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多