I need to limit the point inside the DisplayObjectartist provided to me.
I got this working, but only for cases where the cursor is still inside bounds.
The restricted 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 {
}
}
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 implement the other half of the function? I am aware that Sprite startDragaccepts arguments where the second is a constraint rectangle, but in my case boundsthey are arbitrary shape.
When an object is dragged out of bounds, I want to calculate the closest point from the cursor to the polygon bounds.
Just note that there boundsmay be holes.
Edit:
, , , , ( , hitTestPoint !) .

(: liranuna.com)