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

发布于 2024-11-09 03:08:17 字数 1306 浏览 0 评论 0原文

我正在尝试放大容器/父影片剪辑,以便有效地放大到其子级之一引用的点。我已经弄清楚如何使用 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's Toy Shop”周围的某个地方 - 我想象这是在树剪辑补间之前舞台的中心点,以便“Jon Anderson”会处于舞台中央。

截图

I'm trying to scale a container/parent movie clip up so that I effectively zoom in to a point referenced by one of its children. I've figured out how to use globalToLocal to get that point at the center of the stage, but the problem is the registration point for the container clip is (and needs to stay) at the upper left, so when I scale the container clip up, the point does not stay in the center of the screen. Here's my code:

//REVISED:

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})

    }

When I do this, the zoomed point ends up being somewhere around "Mabel Greer's Toy Shop" - which I imagine was the center point of the stage before the treeClip was tweened so that "Jon Anderson" would be at the center of the stage.

screenshot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪花飘飘的天空 2024-11-16 03:08:17

您需要在缩放并补间 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
}

You need to calculate the destination position of the upper left corner after scaling and tween the x and y properties to it.

The most simple way is to use matrices:

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文