开发者

Drag and drop in as3 on specific path (ex bezier curve)

I need to implement a drag and drop functionality开发者_开发知识库, where I can define and constraint the route of the draggable object. Like in http://www.kirupa.com/forum/showthread.php?t=330302 , only that i have the paths designed and not calculated by a math function. So, in fact, as mouse moves I need to tell the object to follow the custom path/movieclip.


As in your Kirupa example, in the MouseMove handler you'll take the moment-by-moment x and y of the dragged item and recalculate them. To confine the item to a vertical line, for example, you would set x back to the x the item began with, while freeing y to follow the mouse.

In your case, you need an x-and-y recalculation that can 1) determine whether the move is or is not on your path, and 2) if not, shift it to the nearest point on that path (whatever "nearest" means to you).

Maybe collision detection? If no collision (the item is off the path) then shift the item in some direction (along the horizontal, or the vertical...) until you get that collision.

Good?

If StackOverflow has no problem with it, maybe you could report back when you have this worked out?

John Hicks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜