Reputation: 13
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?
Upvotes: 1
Views: 358
Reputation: 658
Use Pythagorean, like in this example:
http://www.flepstudio.org/forum/tutorials/501-pythagorean-theorem-actionscript-3-0-a.html
Upvotes: 1
Reputation: 317
I'm not sure how many objects you'll be having on the screen at any one time, but how about cycling through all the children in the movieclip/stage and checking against each one. Something like-
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));
}
}
}
Or you could extend that to returning an array of MovieClips by just changing the return type
function prox(limit:int):Array{
adding an array var and changing the code inside the if to
array.push(MovieClip(stage.getChildAt(i));
and
return array;
Upvotes: 0