缩放和平移问题 (AS3)



我在AS3中的平移手势遇到问题。据我所知,制作这个:

function fl_PanHandler(event:TransformGestureEvent):void
{
    if (escenario.scaleX && escenario.scaleY == 1)
        {
            trace("MAX ZOOM!");
        }
    else
        {
            event.currentTarget.x +=  event.offsetX;
            event.currentTarget.y +=  event.offsetY;
        }
}

好的。现在,如果我进行缩放,缩放比例将大于1,因此,我可以平移。但是平底锅出了我正在放大的电影剪辑。

项目是500x500,所以,我只需要在500x500中平移,而不是闪光灯的白色背景(500x500的项目有黑色背景,在MC中,是要平移的MC。

您只需要放入一些约束:

var target:DisplayObject = event.currentTarget as DisplayObject;
target.x +=  event.offsetX;
target.y +=  event.offsetY;
//if the x or y is greater than 0, that means you can see the left/top edge of the target, so make it go back to 0
if(target.x > 0) target.x = 0;
if(target.y > 0) target.y = 0;
//the stage width less the target width should be negative so long as the target is bigger than the stage.  
//It will get the x point that would make the right edge line up with the stage's right edge.
if(target.x < stage.stageWidth - target.width){
    //so if the x is less than that point (which would make the right edge of target visible), force the x back so the right edges align
    target.x = stage.stageWidth - target.width;
}
if(target.y < stage.stageHeight - target.height){
    target.y = stage.stageHeight - target.height);
}

最新更新