2012-09-27 28 views
0

我想限制将动画片段拖动到名为“遮罩”的遮罩。可拖动的MC的名字是mapcontainer.themap。它的父母,mapcontainer,与舞台成比例缩放。我如何限制被拖动的MC到面具?下面的代码适用于加载,但不适用于舞台缩放时。限制拖动影片剪辑进行遮罩,使用舞台&mc缩放

function constrainMap():void { 
    leftedge = themapmask.x+mapcontainer.themap.width/2-mapcontainer.x; 
    rightedge= themapmask.x+themapmask.width-mapcontainer.width/2-mapcontainer.x; 
    topedge = themapmask.y+mapcontainer.themap.height/2-mapcontainer.y; 
    bottomedge = themapmask.y+themapmask.height-mapcontainer.height/2-mapcontainer.y; 
    if (mapcontainer.themap.x>leftedge) mapcontainer.themap.x=leftedge; 
    if (mapcontainer.themap.y>topedge) mapcontainer.themap.y=topedge; 
    if (mapcontainer.themap.x<rightedge) mapcontainer.themap.x=rightedge; 
    if (mapcontainer.themap.y<bottomedge) mapcontainer.themap.y=bottomedge; 
} 

回答

1

Sprite.startDrag函数接受特别是对于阻力面积约束的第二个参数,和DisplayObject.getBounds函数返回一个矩形的边界的所施加的说法DisplayObject的上下文中的对象。所以,基本上,你需要做的是:

mapcontainer.themap.startDrag(false /*or true*/, themapmask.getBounds(mapcontainer)); 

你可以放下整个constrainMap函数。

+0

这不起作用 - 可能是因为可拖动的剪辑的注册点位于中心。有任何想法吗? – lgriffin

+0

是的,所以在这种情况下,您需要对发送给startDrag的矩形进行一些更改,如下所示: –

+1

@ user1342133 var rect:Rectangle = themapmask.getBounds(mapcontainer); mapcontainer.themap.startDrag(false/*或true * /,new Rectangle(rect.left + mapcontainer.themap.width/2,rect.top + mapcontainer.themap.height/2,rect.width - mapcontainer.themap.width ,rect.height - mapcontainer.themap.height))' –

相关问题