【发布时间】:2011-01-24 06:07:21
【问题描述】:
我需要在艺术家给我的DisplayObject 内限制一个点。
我让它工作了,但仅适用于光标仍在 bounds 内的场合。
受限对象称为limited。
function onSqMouseMove(event:MouseEvent) {
if(bounds.hitTestPoint(event.stageX, event.stageY, true)) {
limited.x = event.stageX;
limited.y = event.stageY;
} else {
/* Find closest point in the Sprite */
}
}
limited.addEventListener(MouseEvent.MOUSE_DOWN, function(event:MouseEvent) {
stage.addEventListener(MouseEvent.MOUSE_MOVE, onSqMouseMove);
});
limited.addEventListener(MouseEvent.MOUSE_UP, function(event:MouseEvent) {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onSqMouseMove);
});
我该如何实现另一半功能?我知道 Sprite 的 startDrag 接受参数,其中第二个是约束矩形,但在我的情况下,bounds 是任意形状。
当对象被拖出边界时,我想计算从光标到bounds'多边形的最近点。
请注意bounds 可以有“洞”。
编辑:
需要明确的是,我不想查找某个点是否在 MovieClip 内部,我想要距离 MovieClip 外部的一个点最近的点(注意 hitTestPoint 失败 !) 到它的边界。
(来源:liranuna.com)
【问题讨论】:
-
你的边界对象是不是 getPixel() 会给你一种颜色来帮助你确定它是在边界内还是在边界外?即与外面不同的纯色?
-
hitTestPoint就是这样做的。
标签: flash actionscript-3