快讯:最近点到影片剪辑 [英] Flash: Closest point to MovieClip

查看:137
本文介绍了快讯:最近点到影片剪辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要的艺术家在的DisplayObject 给出一个约束点给我。

I need to constrain a point inside a DisplayObject given to me by the artist.

我得到了它的工作,但只为光标还在里面范围的occations。
有限的对象被称为限制

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);
});

我如何去实现该功能的另一半?我知道精灵的的startDrag 接受参数,其中第二个是约束矩形,但对我来说,范围是任意形状。

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'.

需要明确的是,我不希望找点是否里面的影片剪辑或没有,我想从影片剪辑(外点的最近点的请注意hitTestPoint的失败的!),以它的边界。

To be clear, I don't want to find if a point is inside the MovieClip or not, I want the closest point from a point outside the MovieClip (note that hitTestPoint fails!) to the bounds of it.

推荐答案

您可以开始在鼠标的位置,并开始一发不可收拾做点击测试的每一个像素。这将导致在相当长的循环,但取决于你的使用情况它应该履行合理确定。这只能通过测试看看。

You can start at the mouse position and start spiraling out doing the hit test for every pixel. This will result in a long loop but depending on your use case it should probably perform reasonably ok. This you can only see by testing.

这篇关于快讯:最近点到影片剪辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆