1 Reply Latest reply on Feb 26, 2007 10:22 PM by kglad

    Problems using hitTest in my simple flash game

    therooster6
      So I am trying to get my blaster movie clips to hitTest correctly against my enemy movie clips.

      When I press the space bar, I run this code from my player movie clip:
      blastCount++;
      _root.blast.duplicateMovieClip("blast"+blastCount, blastCount);
      _root["blast"+blastCount]._visible = true;

      This will attach my blast movie clip, which has it's own movement information, and thus zips across the screen just f ine.

      I am also creating enemy movie clips at random y positions with the following code:
      viruscount++;
      _root.virus.duplicateMovieClip("virus"+viruscount, viruscount);
      _root["virus"+viruscount]._visible = true;

      These of course have their own movement info, and work just fine as well.

      The problem comes when I want to hitTest these two objects against one another. I am constantly adding more blasts and more enemies, so I'm not exactly sure how I can test these against each other given that there isn't just 2 objects, but many of them, with varying names (blast1, virus7, etc). I was thinking about using some sort of array to store names and check against each other, but I am still a bit lost...

      Any help would be greatly appreciated!
        • 1. Re: Problems using hitTest in my simple flash game
          kglad Adobe Community Professional & MVP
          you can use the push method of arrays to add your movieclips to an array and you can use the splice method to remove them.

          you would probably want two arrays. one for the blast movieclips and one for the virus movieclips.

          you would probably want to use one master loop that repeatedly checks for a positive hitTest between elements of the blast array and elements of the virus array.

          when movieclips are off-stage or destroyed remove them from their array so the array length is kept managable and your loops are more efficient.