Skip to main content
October 19, 2006
Question

Advanced hitTest

  • October 19, 2006
  • 16 replies
  • 724 views
I am trying to make a fun bullseye game for my friends, but I can't seem to get it to tell me exactly which target I hit in the bullseye target. In my bullseye, I have 60 polygons placed on the bullseye. I want to determine which ONE I hit, not two, or three, or four, etc.

This is what I have:

for(var i = 0; i <= 59; i++) {
if(circle.circle_hit.hitTest(bullseye['target_'+i])) {
trace(i); // I get 3 traces, I only want one
}
}

The circle_hit mc is 2x2, thanks in advance
This topic has been closed for replies.

16 replies

kglad
Community Expert
Community Expert
October 22, 2006
kglad@REMOVETHIS_hotmail.com
October 22, 2006
Could you send me your email address so I can send the fla file to you? Or tell me how I can allow you to upload it through a browser (I don't know how to the second one, I would prefer email)
kglad
Community Expert
Community Expert
October 22, 2006
create a new fla that demonstrates the problem. it need only contain your bullseye, crosshair and hitTest.
October 22, 2006
Sorry for the long reply.

No, I am not calling the hitTest while it is still spinning, it completely stops then runs the hitTest() function. And I rather not give out my fla file because I am very cautious of whom I give it to, and what they will do with it, ecspecially this fla file (please don't take that personal, but I am sure you understand).

Is ther any chance you sharing what you would do in this situation? How would you grab the exact hexagon that the circle_hit collides with, without grabbing the surrounding hexagons?

the only thing I can think of is:

for(var i = 0; i <= 59; i++) {
if(circle_hit.hitTestthis['shard_'+i]) and !hit) {
hit = true;
trace i;
}
}

what's your's opinon that? Or something along those lines? But that doesn't really quite work (I have tried)
kglad
Community Expert
Community Expert
October 20, 2006
it will return the only hexagon(s) it hits. the problem is your 2x2 circle_hit is hitting more than one bullseye["target_"+i].

are you calling your hitTest() while the target is still spinning and you're calling it more than once? if that's not the problem you can post a link to your fla and i'll correct it for you.
October 20, 2006
well, that is the point of it. It's a bulleyes/target game. The bullseye/target is spinning at random speeds with two crosshairs moving vertically (_y) and horizontially (_x). After the user stops the crosshairs, it finds the point of _x and _y and places a mc circle_hit (2x2) in it's position to show to the user that it hit that precise spot on the target/bullseye. Does that make sense so far?

Then when I do a hitTest(), it returns 2-4 of the hexagon movieclips that circle_hit hit. But I only want it to return just one. Does this give you a better idea of what I am trying to do? Because I want it so that it returns only that hexagon it hits (let's say it's 10 points for each hexagon), so it adds ONLY 10 points to the users score, not 40 or 50 points.

Hopefully this helps, because I can't exaplin further in detail what this bullseye game does, but just that.

"but at this point i have no idea which movieclip you want returned when more than one have a positive hitTest()."

just the one that circle_hit (2x2) is visually in contact with.
kglad
Community Expert
Community Expert
October 20, 2006
there's a solution. but noone but you can determine how to single out one movieclip amoung several that return a positive hitTest(). if you can draw or articulate how to designate the movieclip of interest, i'm pretty sure i can help suggest the code to do the same.

but at this point i have no idea which movieclip you want returned when more than one have a positive hitTest().
October 20, 2006
I am sorry, I am not quite following you.

From what I am understanding, there might not be a solution to what I am doing, correct? If possible, can you please provide some code, or a small snippet, to help me understand a bit (if that isn't too much to ask)
kglad
Community Expert
Community Expert
October 20, 2006
the highest depth may not work for you. i only said it's usually the movieclip of interest.

if your movieclips overlap at their borders and you have positive hitTest() over a border returning more than one movieclip, in which movieclip are you interested?
October 19, 2006
Yes, each hexagon is it's own individual movieclip, but I still don't follow; sorry.

But if I set each hexagon to certain level, and then run a hitTest() and get those hexagons that hit the circle_hit mc (2x2), how will the highest depth get which one it hit? Let's say for example, it hit the far left hexagon in the top right corner, if I were to do a hitTest() it would return that hexagon and several of the surrounding hexagons. AND IF the surrounding hexagons were on a higher depth, it would return to me that hexagon mc. The same goes for all edges of the hexagon, does this make sense?

Hopefully you understand why I can't understand how a highest depth will work.

Thank you