[英]Zoom & Panning questions (AS3)
我在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而不是使用閃光燈的白色背景(在MC中,500x500的項目具有黑色背景,這就是要平移的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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.