Problem with hitTest!

  • slein
  • Born
  • Born
  • slein
  • Posts: 2

Post 3+ Months Ago

Hello!

I'm trying to create a game in which you can catch butterflies with a net, gaining points.
If more than one butterflies get caught in the net, there is a bonus of 1000 points.
(The net starts dragging as the game starts and its name is net_mc).

Actually, there are three instances of the butterflies (fly1_mc, fly2_mc, fly3_mc) that move randomly on the stage.

The problem is that when the net approaches more than one butterflies, it only works for one of the butterflies, so there's no bonus.

I'm not very good at flash but I must do this for a college assignment. :cry:

I thought that something like this would work, but unfortunately, it doesn't:

if(net_mc.hitTest(fly1_mc) && net_mc.hitTest(fly2_mc) && net_mc.hitTest(fly3_mc))
{
score=score + 1000;
}

Please help me, I've been trying to find this for days....
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

well I'm trying to think how to do this off the top of my head and coming up blank, However part of the problem is that right now your testing to see if ALL 3 movie clips are in the net not just any 2. I assume there's an easier way to do this but you could test if:

fly1 AND fly 2 OR fly1 AND fly3 OR fly2 AND fly3 are in the net

In actionscript AND is && OR is || (pipe shift + \ )

However, this can't be the best way to do it since it would be come impossible very quickly if you started adding 3 copies of fly2, etc
  • krismeister
  • Graduate
  • Graduate
  • krismeister
  • Posts: 202

Post 3+ Months Ago

You could keep an array of all the elements you've caught in the net, and when the array.length is more than 1 you know that you have 2 or more.
  • slein
  • Born
  • Born
  • slein
  • Posts: 2

Post 3+ Months Ago

Thank you very much guys!

graphixboy, I've tried this but it still doesn't work....

krismeister, I think that the problem could be solved by using an array, but I'm confused... can you explain it?
How will the elements be added in the array each time? Will I have to use hitTest for each butterfly? How will I know that they all get caught at the same time?
  • krismeister
  • Graduate
  • Graduate
  • krismeister
  • Posts: 202

Post 3+ Months Ago

I misunderstood, I thought once you caught it in your net and it stayed in your net then you wanted to detect them catching a second one. The array would be easiest for that.

for the simultanious catches a simple way is --
an onEnterFrame:
Code: [ Select ]
var x=0;

If(net_mc.hitTest(fly1_mc) ){
x++
}

If(net_mc.hitTest(fly2_mc) ){
x++
}

If(net_mc.hitTest(fly3_mc) ){
x++
}

if(x>1){trace('you caught more than one')};
  1. var x=0;
  2. If(net_mc.hitTest(fly1_mc) ){
  3. x++
  4. }
  5. If(net_mc.hitTest(fly2_mc) ){
  6. x++
  7. }
  8. If(net_mc.hitTest(fly3_mc) ){
  9. x++
  10. }
  11. if(x>1){trace('you caught more than one')};

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 7 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.