Skip to main content
April 14, 2006
Answered

hitTest issues

  • April 14, 2006
  • 17 replies
  • 909 views
Ive started writing the 'hitTest' code for the game, i wasnt sure how, since i hadnt' tried it before- but after a short tutorial it's simple enough. However, i am running into problems.

Currently, my stage is set up with a ship, that fires bullets, at the top of the stage, i have a long movie clip that will act as a 'wall', when the bullets collide with the wall they should stop moving, and 'blow up'. I have my animations, and all the fun stuff down- but my hit test isnt working one bit!

here is the code for the hit test- it runs in my main _root enterframe loop.

thanks.
This topic has been closed for replies.
Correct answer kglad
you're creating 10 bullets but you're only checking a hitTest on 5 of them. that's a problem.

p.s. you don't need to remove your bullet movieclips because you're removing them when you reuse their depths during their creation.

17 replies

kglad
Community Expert
Community Expert
April 19, 2006
you're welcome.
April 18, 2006
kglad- thats a huge improvement- thanks so much.
kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
April 18, 2006
you're creating 10 bullets but you're only checking a hitTest on 5 of them. that's a problem.

p.s. you don't need to remove your bullet movieclips because you're removing them when you reuse their depths during their creation.
April 18, 2006
'thanks
kglad
Community Expert
Community Expert
April 18, 2006
i have the file. you can remove it.
April 18, 2006
kglad,
i totaly understand - im sorry to hear that. I will post the file up- i dont think much will happen from the issue of showing it- i will just pull it off my server after you retrieve the file.

-edit-
kglad
Community Expert
Community Expert
April 18, 2006
no, i've had too many problems with forum users taking advantage of that situation using me as their personal flash editor and loading my mailbox with fla files that need editing.

if you can extract just the code and graphics that display the problem and post a link to that fla, that would work, too.
kglad
Community Expert
Community Expert
April 18, 2006
post a link to your fla that displays the problem.
April 18, 2006
KGlad,
Is there a way i can privately send you the link- this is for a corporate customer, and i cannot afford to throw the .fla around on a public message board.

thanks so much.
kglad
Community Expert
Community Expert
April 17, 2006
you're welcome.
April 17, 2006
My only problem- it seems as if half the bullets collide- and the others dont. It seems like the first few of the cycle will collide, but rest skip right past- im wondering if this has to do with the depth of 'tWall' and 'bullet"

-edit-

Ive swapped depth's for my tWall- this doesnt do anything. Ive also slowed the bullets again to see what was happening- I counted out of 11bullets that passed the wall- 3 collided, the rest passed through easily.
April 17, 2006
--EDIT--
I slowed the bullet speed to test- and it worked perfectly. Thanks!

this is code that i had borrowed from a existing tutorial- and modified to fit my game for the 'wall' collision.

var bulleti = 6;
while (--bulleti>0) {
if (_root.tWall.hitTest(eval("_root.bullet"+bulleti))) {
eval("_root.bullet"+bulleti).gotoAndPlay(2);
trace("hit");
}
}