Flash: Closest point to MovieClip

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 {
        /* 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 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 !) .

alt text
(: liranuna.com)

+3
5
+1

, , , ( , ). , , , , , .

:

  • , n- (, 5x5 ), , (getColorBoundsRect( 0xff000000, 0, false ); ?). , , , , ( , , ..). , - , , , , . , .

  • , , / hitpoint. : 0, : 0, , , (, 5 ) , . ( Grant Skinners, viatropos), , , , , hittests , 30 , , .

, !

+1

, . , , , . .

+1

, , :

  • 20 . , . , . , . ( , , ). - : Point.interpolate(closestRef, nextClosestRef, factor). , 100% , ( ). , , , , , , .
  • " ". Google - .
  • , , . , , 5 , , . , , . . , . ( , ), hitdetect . , . Point.polar(radius, angle).add(cursorPosition), .
  • , 3, , Flash Platform. , , .

API , , , .

0

Source: https://habr.com/ru/post/1735637/


All Articles