5 Replies Latest reply on Mar 18, 2007 8:17 AM by kglad

    hit detection without on enterframe?

    ahref
      hi there,

      i was wondering if there was a way to do hit detection without the on enterframe clip event. This is because if there are alot of things that need to be checked it could get a bit laggy.

      thanks
        • 1. Re: hit detection without on enterframe?
          Level 7
          ahref,

          > i was wondering if there was a way to do hit detection
          > without the on enterframe clip event.

          Absolutely. You may invoke the MovieClip.hitTest() method whenever you
          like. It could be an onEnterFrame even, a mouse click, a timer, just
          randomly ...

          > This is because if there are alot of things that need to be
          > checked it could get a bit laggy.

          If you've got to check a lot of things, you've got to check 'em. If you
          must check repeatedly, then it doesn't much matter if you use an
          onEnterFrame event or, say, a setInterval() loop. If you know the position
          and surface area of your movie clip, you can certainly perform "imaginary"
          hit tests against those coordinates. That would probably be more efficient
          because it would omit a method call.


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: hit detection without on enterframe?
            kglad Adobe Community Professional & MVP
            you can trigger a hitTest() any number of ways. however, if you have no idea when a positive (or negative) hitTest() will occur, then you must use an continual loop of some kind.
            • 3. Re: hit detection without on enterframe?
              Level 7
              This is an interesting question
              What is your context?
              "ahref" <webforumsuser@macromedia.com> wrote in message
              news:ethplk$pgu$1@forums.macromedia.com...
              > hi there,
              >
              > i was wondering if there was a way to do hit detection without the on
              > enterframe clip event. This is because if there are alot of things that
              need to
              > be checked it could get a bit laggy.
              >
              > thanks
              >


              • 4. Re: hit detection without on enterframe?
                ahref Level 1
                well i am making a space exploration game. Much like the game Star control 2. in such a game there are alot of things that will need checking on a solar system screen;

                planet with ship
                space station with ship
                enemy ship with planet
                enemy ship with ship
                ship with edge of solar system(leads to hyperspace)

                and probably more i havent thought of.

                in particulary busy solar systems there is a lot tocheck and i thought this may get laggy.

                thanks
                • 5. Re: hit detection without on enterframe?
                  kglad Adobe Community Professional & MVP
                  because you don't know when collisions will occur, use a continual loop like setInterval() or onEnterFrame. you only need one loop to check all collisions.