2 Replies Latest reply on Feb 18, 2011 4:28 AM by Ned Murphy

    Character Running Animation Stuck

    UltimateFlashxz Level 1

      Hey all.

       

      im having a little issue with my character animation when i use the arrow keys to move him.

      everything works but the fact that the "Running" animation wont stop.

      i tryed i few things and i only end up breaking the code.

      any ideas?

       

      if (Key.isDown(Key.RIGHT)) {

      this.gotoAndStop(2);

      _x += speed;

      }

      if (Key.isDown(Key.LEFT)) {

      this.gotoAndStop(3);

      _x -= speed;

      }

        • 1. Re: Character Running Animation Stuck
          UltimateFlashxz Level 1

          ive tryed using ELSE

           

          if (Key.isDown(Key.RIGHT)) {

          this.gotoAndStop(2);

          _x += speed;

          }else{

          this.gotoAndPlay(1);

          }

          if (Key.isDown(Key.LEFT)) {

          this.gotoAndStop(3);

          _x -= speed;

          }else{

          this.gotoAndPlay(1);

          }

           

          moving to the right works but when i try to go left he only moves from standing to the first frame in the running animation and back again.

          • 2. Re: Character Running Animation Stuck
            Ned Murphy Adobe Community Professional & MVP

            Is there any other code surrounding these controls?  You haven't explained much about how this is all set up/intended to work, and I don't like to assume things.... but I will base my offering on this.gotoAndPlay(1); is telling it to go to a frame where it appears to be standing still (you should probably use gotoAndStop(1) for consistency and to match intention).

             

            The way you have it now, if the character is not heading right, then you tell it to stand still, but then you test for the left and do the same thing.  What you might try instead is not separating them but rolling them into a conditional set so that the command to stand occurs only when neither key is being used...

             

            if (Key.isDown(Key.RIGHT)) {

                 this.gotoAndStop(2);

                 _x += speed;

            } else if (Key.isDown(Key.LEFT)) {

                 this.gotoAndStop(3);

                 _x -= speed;

            } else{

                 this.gotoAndStop(1);

            }

             

            and you might even want to throw in something for the folks who try to run both ways at once..

             

            if (Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT)) {

                 this.gotoAndStop(2);

                 _x += speed;

            } else if (Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) {

                 this.gotoAndStop(3);

                 _x -= speed;

            } else{

                 this.gotoAndStop(1);

            }