我在AS3中遇到Pan手势问题。据我所知,做到这一点:
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中进行平移而不是闪光灯的白色背景(500x500的项目具有黑色背景,在MC中,是将要淘汰的MC。
答案 0 :(得分:1)
你只需要加入一些约束:
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);
}