I'm trying to find a way so that instead of telling me if the hitTest is true or false, it tells me what movie clip is colliding with my main movie clip.
1. Workout the area classifies as collision. For example, if a MovieClip is within the area within TargetMovieClip location plus/minus 50px it classifies as collision.
2. Go through all the MovieClips on Stage and check if the location is within the area defined.
If I express above in AS it would be:
[tt]// main timeline
onEnterFrame = function ():Void {
for (var s in this) {
if (typeof (this) == "movieclip") {
if (s != "mcTarget") {
if (this._x>mcTarget._x-50) {
if (this._x<mcTarget._x+50) {
if (this._y>mcTarget._y-50) {
if (this._y<mcTarget._y+50) {
trace(s+" is collided with mcTarget!");
}
}
}
}
}
}
}
};
//[/tt]
Oh one more thing
//
function detectCollision(what) {
for (var s in this) {
if (typeof (this) == "movieclip") {
if (s != what) {
if (this._x>what._x-50) {
if (this._x<what._x+50) {
if (this._y>what._y-50) {
if (this._y<what._y+50) {
trace(s+" is touching");
}
}
}
}
}
}
}
}
onEnterFrame = function () {
detectCollision("player");
};
//
I have that, and it keeps tracing "instance3 is touching"
Do you know why?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.