flash as3放大(放大)到剪辑中的特定点

时间:2011-05-24 15:30:53

标签: flash actionscript-3

我正在尝试缩放容器/父级影片剪辑,以便我有效地放大到其子级之一引用的点。我已经想出如何使用globalToLocal来获取舞台中心的那个点,但问题是容器剪辑的注册点是(并且需要保持)在左上角,所以当我缩放容器剪辑时向上,该点不会停留在屏幕的中心。这是我的代码:

//修:

var stageCenter = new Point(int(stage.stageWidth/2),int(stage.stageHeight)/2);
    var parPointLocal = parRef.globalToLocal(stageCenter);
    TweenMax.to(treeClip,.5,{x:parPointLocal.x,y:parPointLocal.y,onComplete:doZoom});

    function doZoom():void {
        var zoomPoint = zoomToMember(treeClip,stageCenter,2);

        function zoomToMember(target:MovieClip, center:Point, scale:Number):Point {
            var m:Matrix = new Matrix();
            m.translate(-center.x, -center.y);//move the center into (0,0)
            m.scale(scale, scale);//scale relatively to (0,0) (which is where our center is now)
            m.translate(center.x, center.y);//move the center back to its original position
            return m.transformPoint(new Point());//transform (0,0) using the whole transformation matrix to calculate the destination of the upper left corner
        }

        TweenMax.to (treeClip,.5,{x:zoomPoint.x,y:zoomPoint.y,scaleX:2,scaleY:2})

    }

当我这样做时,缩放的点最终会出现在“Mabel Greer的玩具店”周围 - 我想这是在TreeClip被修补之前舞台的中心点,这样“Jon Anderson”就会出现在舞台。

screenshot

1 个答案:

答案 0 :(得分:3)

您需要在缩放后计算左上角的目标位置,并将x和y属性补间到它。

最简单的方法是使用矩阵:

function scale(target:MovieClip, center:Point, scale:Number):Point {
    var m:Matrix = new Matrix();
    m.translate(-center.x, -center.y);//move the center into (0,0)
    m.scale(scale, scale);//scale relatively to (0,0) (which is where our center is now)
    m.translate(center.x, center.y);//move the center back to its original position
    return m.transformPoint(new Point());//transform (0,0) using the whole transformation matrix to calculate the destination of the upper left corner
}