3 Replies Latest reply on Mar 15, 2010 10:45 PM by kglad

    slow script error

    VicTropic

      I'm tryimg to make a platformer game were the level moves instead of you, but for some reason my while loop is a infinite loop. env is the level, "this" is the character and lev is the ground. the code is so that my guy doesn't sink in the ground, and if you know a better way to state that in flash the please show.

       

      levellocationx= env._x -xspeed

      levellocationy= env._y -yspeed

      while (env.lev.hitTest(this._x,this.y,true)){

                 levellocationy++;

                yspeed=0

                gravity=0

      }

      env._x=levellocationx

      env._y=levellocationy

        • 1. Re: slow script error
          kglad Adobe Community Professional & MVP

          while-loops and for-loops execute from beginning to end before anything is updated on-stage.  so, they are not appropriate for use in animating anything.

           

          use an onEnterFrame loop or setInterval() loop for animation.

          • 2. Re: slow script error
            VicTropic Level 1

            yes ,but what im trying to do is have my character hit the ground and pop up one pixel above the ground before the next frame, well except inversely where the ground moves instead. For that to work I would need a while loop.

            • 3. Re: slow script error
              kglad Adobe Community Professional & MVP

              if you only wantted to move 1 pixel, you wouldn't need a while-loop.  if you need to move a variable amount of pixels you could use a while-loop.  but you better make sure that hitTest will be false when that variable increments enough.