3 Replies Latest reply on Mar 29, 2011 6:26 PM by Rothrock

    Collisions: Recovery Time


      Right now I have, in my game, a numeric health counter beginning at 100.

      I have a collision set to where when in contact, the health subtracts by 5.

      However, I need a recovery timer for the player so he doesn't keep getting hit by 5 every milisecond.

      How do you set up a timer where the collision has to wait for 2 second before the player could be hit again?

        • 1. Re: Collisions: Recovery Time
          Rothrock Level 5

          I would probably handle the score setting with a function. Something like this:


          var score:Number=100;

          var hitDelay:Number=2000;

          var lastHitTime:Number=0;

          var maxScore:Number=200;


          function setScore(n:Number){


















          Then everytime you want to adjust the score you just call the function.


          setScore(-5) \\ some kind of negative hit

          setScore(5) \\ ate a power up bar or something....


          That way you put all the logic and testing in one place. It makes it easier to maintain and adjust as you work out exactly what you want to do....

          • 2. Re: Collisions: Recovery Time
            EranthisAconite Level 1

            How do you display the score?

            • 3. Re: Collisions: Recovery Time
              Rothrock Level 5

              How do you want to display the score? Is it a graphic power bar or just a text readout?


              In any event you put the code at the end of the function.