首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用stage和mc缩放将影片剪辑的拖动限制为蒙版

使用stage和mc缩放将影片剪辑的拖动限制为蒙版
EN

Stack Overflow用户
提问于 2012-09-28 07:45:17
回答 1查看 315关注 0票数 0

我想把电影剪辑的拖拽限制在一个叫做themapmask的遮罩上。可拖动的mc的名称是mapcontainer.themap。它的父级mapcontainer与stage成比例缩放。如何将拖拽的mc约束到遮罩?下面的代码在加载时有效,但在缩放舞台时不起作用。

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-28 08:40:33

Sprite.startDrag函数接受第二个参数,特别是对于拖动区域约束,而DisplayObject.getBounds函数在参数DisplayObject的上下文中返回一个矩形,其中包含应用到的对象的边界。所以,基本上,你需要做的是:

代码语言:javascript
复制
mapcontainer.themap.startDrag(false /*or true*/, themapmask.getBounds(mapcontainer));

而且你可以完全放弃整个constrainMap函数。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12631692

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档