【问题标题】:AS3: Scale movieclip at another movieclips position?AS3:在另一个动画剪辑位置缩放动画剪辑?
【发布时间】:2013-04-18 10:35:32
【问题描述】:

我正在尝试根据影片剪辑的 x 和 y 位置缩放基本图像?基础镜像镜像也是一个 MC。

infoIconCompFit.addEventListener(MouseEvent.ROLL_OVER, zoomInCompFit);
infoIconCompFit.addEventListener(MouseEvent.ROLL_OUT, zoomOutCompFit);

function zoomInCompFit(event:MouseEvent):void {
   TweenLite.to(baseImage, 1, {scaleX:2, scaleY:2});
}

function zoomOutCompFit(event:MouseEvent):void {
   TweenLite.to(baseImage, 1, {scaleX:1, scaleY:1});
}

我的意思是;是否可以在舞台上另一个影片剪辑的 x 和 y 位置缩放影片剪辑?就像我希望基本动画剪辑在鼠标 ROLL_OVER 上另一个动画剪辑的位置缩放(放大)然后在鼠标 ROLL_OUT 上缩小。

我让它在处理程序上放大和缩小,但我如何让它相对于其他 MC 放大到那个位置?

(之前)http://www.marketingfanatics.co.za/images/exampleNormal.jpg (后)http://www.marketingfanatics.co.za/images/exampleZoomedl.jpg

【问题讨论】:

  • 我不明白你想要什么。您能否附上一张图片来描述您预期发生的事情之前和之后的情况?
  • @prototypical 请看上面的图片来明白我的意思。
  • @prototypical 我需要在蓝色信息图标的 x 和 y 位置缩放主图像。我什至不知道这是否可能,但我一直有这种感觉,它不应该这么复杂。就像我错过了什么。
  • 好的,我明白你的意思了。

标签: actionscript-3 zooming scale movieclip


【解决方案1】:

是的,你可以。但是您需要编写一些代码并记住这些对象的转换枢轴在哪里。

/**
         * Calculate position and dimensions of image to zoom.
         * @param   img - image to animate, need to have transformation pivot in top left corner!
         * @param   point - point to zoom in (or null if zoom out) that will be new center of image
         * @param   scale - scale in zoom in
         * @param   viewWidth - container width
         * @param   viewHeight - container height
         * @return  object for tween engine with parameters to animate
         */
        private function centerOn(img:DisplayObject, point:Point=null, scale:Number=2, viewWidth:Number=300, viewHeight:Number=200):Object
        {
            var r:Object;
            var mm:Matrix = img.transform.matrix;
            img.transform.matrix = new Matrix();

            if (point == null) { // oryginal size
                r = { x: 0, y: 0, width: img.width, height: img.height };
            }else { // zoom
                img.scaleX = img.scaleY = scale;
                point.x *= scale;
                point.y *= scale;
                img.x = -point.x + viewWidth / 2;
                img.y = -point.y + viewHeight / 2;
                r = { x: img.x, y: img.y, width: img.width, height: img.height };
            }
            img.transform.matrix = mm;
            return r;
        }

使用示例:

TweenLite.to(baseImage, 1, centerOn(baseIMG, new Point(100, 150))); //zoom in
TweenLite.to(baseImage, 1, centerOn(baseIMG)); //zoom out
centerOn(img, new Point(200, 135), 4, stage.stageWidth, stage.stageHeight); // to fit stage size

请记住,您的显示对象没有被遮盖,有时(在边界附近缩放)您会看到它下面的场景!

PS。代码测试。

【讨论】:

    猜你喜欢
    • 2018-01-13
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 2013-08-23
    • 1970-01-01
    • 2019-08-26
    • 1970-01-01
    • 2021-12-23
    相关资源
    最近更新 更多