flash actionscript:
[quoted text, click to view] "SIMphilip" <webforumsuser@macromedia.com> wrote in message news:dddr6p$5i7$1@forums.macromedia.com... > Hello everyone, > > Is there a way to check to see if two objects are overlapping using > ActionScript? It seems to me that there should be a way to do this, > since > buttons have a hit area...shouldn't there be some sort of way to see > if two > movie clips' "hit" areas intersect?
Look up hitTest tralfaz
Hello everyone, Is there a way to check to see if two objects are overlapping using ActionScript? It seems to me that there should be a way to do this, since buttons have a hit area...shouldn't there be some sort of way to see if two movie clips' "hit" areas intersect? In case anyone is wondering, I need to know this because I am designing a game in Flash, and I need to be able to tell when the player (or an NPC) runs into an object that it cannot just walk over. Thanks very much for any help anyone can provide. --Philip
Hello again, Thanks, I tried that...however for some reason it is not working properly :(. I am attaching my code...if you can figure out what I'm doing wrong I'd be really appreciative. Btw, I tried changing the movie clip to a button setting the hit area to be the walls as I had set them to be. Also, note that the walls were a very irregular shape; could it be that the hit area is considered to be everything within the boundaries of the shape that I have drawn, and thus that is why it wasn't working? Oh, and as for what happened...when I ran it as it is in this code, it basically always thought that the two objects overlapped, and so the character couldn't move at all. When I did it with the button instead of the movie clip, it rarely to never said that they overlapped (even when it was supposed to), so the character was free to walk about the stage (and through the walls!), which was not supposed to happen. Thanks again. --Philip function checkCollisions(the_mc:MovieClip,oldX:Number,oldY:Number) { for (var name5 in _root) { if (typeof this[name5] == 'movieclip' || typeof this[name5] == 'object') { //go through the cycle and see if there are any collisions trace(name5); if (name5 == "walls" && the_mc.hitTest(this[name5]) == true) { the_mc._x = oldX; the_mc._y = oldY; trace("wall hit"); } } } }
Don't see what you're looking for? Try a search.
|