Flash: Closest point to MovieClip
Posted
by LiraNuna
on Stack Overflow
See other posts from Stack Overflow
or by LiraNuna
Published on 2010-03-05T18:58:39Z
Indexed on
2010/03/08
11:06 UTC
Read the original article
Hit count: 263
flash
|actionscript-3
I need to constrain a point inside a DisplayObject
given to me by the artist.
I got it working but only for the occations where the cursor is still inside bounds
.
The limited object is called 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);
});
How do I go about implementing the other half of the function? I am aware Sprite's startDrag
accepts arguments, where the second one is the constraint rectangle, but in my case, bounds
are an arbitrary shape.
When the object is dragged outside the bounds, I want to calculate the closest point from the cursor to bounds
' polygon.
Just to note that bounds
can have 'holes'.
© Stack Overflow or respective owner