2013-05-06 153 views
0

我正在開發一個繪圖應用程序,並且遇到了一個問題,並且可能的解決方案是能夠在不改變其透視的情況下水平調整圖像大小(增加或減少寬度)但是以「方向調整大小」結束,這意味着,如果我開始拖動右側調整大小定位點,圖像開始將其寬度增加到右側,而不是始終考慮透視。增加寬度而不移動圖像

所以,我現在要做的是增加寬度,同時我移動圖像寬度/ 2,它可以工作,但是當我必須旋轉圖像時,一切都開始破裂,並且即使我將焦點設置在精靈中間,因爲圖像(包含在精靈內部)x被改變了,這並不重要。

我讀過一些關於矩陣,但我不確定這是否可能。

謝謝。

+0

這可能是你已經盡力了,但你改變的scaleX而不是寬度的實驗?我不確定這是否會導致數據透視表現得更好 – 2013-05-06 19:40:41

回答

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;