Pero44
Pero44

Reputation: 105

Checking if MovieClip is on top of another

I'm generating a number of MovieClips and am putting them on the container on random positions... However, it sometimes happens that one MC is almost directly on top of another...

I could solve this easily if I could somehow check if the random-generated x and y are on top of any other MCs x and y...

Any ideas?

Upvotes: 1

Views: 86

Answers (1)

CyanAngel
CyanAngel

Reputation: 1238

The hitTestPoint() can tell you if your object is over a specific point:

if (myMovieClip.hitTestPoint(myX,myY) == true)
{
   trace("hit detected");
}

You can also use hitTestObject() to detect a collision or overlap with another movieClip:

if (myMovieClip1.hitTestObject(myMovieClip2) == true)
{
   trace("hit detected");
}

Upvotes: 3

Related Questions