缩放和平移问题 (AS3)

Zoom & Panning questions (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,这样我就可以平移了。但是平移超出了我正在缩放的​​ MovieClip。

项目是500x500,所以,我只需要在500x500下平移,而不是flash的白底(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);
}