1

I need to have a point check for objects around it based on distance, and it is not possible to determine what will be on the stage at any given time, so I cannot just trace everything that would near it.

How would I do this so it can also detect what the nearby object is, in addition to detecting the object?

4

2 回答 2

1

使用毕达哥拉斯,就像在这个例子中:

http://www.fepstudio.org/forum/tutorials/501-pythagorean-theorem-actionscript-3-0-a.html

于 2012-08-20T09:32:24.963 回答
0

我不确定您将在任何时候在屏幕上显示多少对象,但是如何循环浏览电影剪辑/舞台中的所有孩子并检查每个孩子。就像是-

function prox(limit:int):MovieClip{
    for(var i:int = 0; i<stage.numChildren;i++)
        if(Math.abs(MovieClip(stage.getChildAt(i)).x - point.x) < limit && 
           Math.abs(MovieClip(stage.getChildAt(i)).y - point.y) < limit){
            return MovieClip(stage.getChildAt(i));
        }
    }
}

或者您可以通过更改返回类型将其扩展为返回一个 MovieClips 数组

function prox(limit:int):Array{

添加一个数组 var 并将 if 中的代码更改为

array.push(MovieClip(stage.getChildAt(i));

return array;
于 2012-08-20T06:12:04.610 回答