16 Replies Latest reply on Oct 22, 2006 8:37 AM by kglad

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
• ###### 1. Re: Advanced hitTest
if your movieclips don't overlap you'll get, at most, one positive hitTest(). if they overlap then you get a positive hitTest() for each that are hit. if you want to single out the topmost one, you can use the getDepth() property of movieclips to see which is topmost.
• ###### 2. Re: Advanced hitTest
How would the getDepth() work? I don't understand how this solve my problem.

Let's say that there are three diamond shapes right next to one another, and I hit the bottom left diamond (let's say these diamonds form a triangle). Furthermore, let's say I hit the bottom left triangle in the same hitTest area as the other two diamonds. How can I tell I hit that bottom left diamond using a getDepth()? (assuming that bottom left diamond is in the middle of the three layers).

• ###### 3. Re: Advanced hitTest
yes
• ###### 5. Re: Advanced hitTest
This is an example of what I mean (it's a small slice/pic of the target):

http://www.gregathons.com/pic.jpg

what happens if the user clicks on the tip of the diamonds, how would I determine if it was THAT diamond, and not the ones it surrounds? Please help
• ###### 6. Re: Advanced hitTest
your jpg is composed of hexagons. but i can't determine whether each hexagon is composed of more than one movieclip and i can't determine whether those hexagons overlap or are composed of overlapping movieclips.

in any case, if you have a hitTest() at an intersection of movieclips in which movieclip are you interested? usually (but not always) it would be the top-most movieclip.

if that's true you could store all the movieclips with the positive hitTest() in an array and return the movieclip with the highest depth.
• ###### 7. Re: Advanced hitTest
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
• ###### 8. Re: Advanced hitTest
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?
• ###### 9. Re: Advanced hitTest
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)
• ###### 10. Re: Advanced hitTest
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().
• ###### 11. Re: Advanced hitTest
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.
• ###### 12. Re: Advanced hitTest
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.
• ###### 13. Re: Advanced hitTest

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)
• ###### 14. Re: Advanced hitTest
create a new fla that demonstrates the problem. it need only contain your bullseye, crosshair and hitTest.