as3闪烁放大到剪辑内的特定点

问题描述

| 我正在尝试放大容器/父级影片剪辑,以便有效地放大到其子级之一所引用的点。我已经弄清楚了如何使用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,{x:zoomPoint.x,y:zoomPoint.y,scaleX:2,scaleY:2})

    }
当我这样做时,缩放点最终位于\“ Mabel Greer \'s Toy Shop \”周围的某个地方-我想这是在TreeClip补间之前舞台的中心点,因此\“ Jon Anderson \”在舞台中央     

解决方法

在缩放和补间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
}
    

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...