PDA

View Full Version : HitTest query


sandesh
10-28-2004, 05:46 AM
Hi everybody

I have tried this but couln't get the way i wanted. Suppose I have two movie clips on root and i want to hitTest one movieclip with another. Now the thing is both the movieclips contain irregular shapes (consider pieces of jigsaw puzzle). But i can't hitTest the border outline of one irregular shape with the border outline of another movieclip.


Maximum i can only assign one movieclip with its exact shape (using the shapeflag).......... not both............... anybody can help me with this ?? :(

emergency_pants
10-28-2004, 10:04 AM
Crazy, isn't it?

Funny how all the books I have seem to have comprehensive sections on collision detection but always seem to skirt around this problem!! :rolleyes:

There's no easy or quick way of doing it. The only way I have found in the past is to take points on each irregular shape and then do a shapeflag hitTest against the shape of another.

This is ok with two or three shapes, but if you have twenty or thirty, then I think it's fairly dodgy.

for example, if your pentagon needs to test against another pentagon:

for (i=1; i<=5; i++) {
if (pentagon2.hitTest(pentagon1["point"+i]._x, pentagon1["point"+i]._y, true)) {
trace("hit!");
}
}


Testing one pentagon against five points of another pentagon.

Maybe thats something in the right direction?

sandesh
10-28-2004, 11:40 AM
Thanks Simon......

But the shapFlag wont be of help much.......... by defining shapeFlag for one movieclip, i can test the collision of the entire irregular shape of one movieclip but i have to define only the x and y co-ordinates of another movieclip....... i mean the collision between the two movieclips will prove to be true only when the actual area of one movieclip collides with only the reference point of another movie clip ....

what i wanted is the actual irregular shape of one movieclip should detect collision when it intersects with any boundary part of another irregular shaped movieclip (and not the bounding boxes)