1 Reply Latest reply on Jun 24, 2010 2:02 AM by DazFaz

    Multiple Animations for a single MovieClip sprite

    Haru_Lance

      Ok, after hours of exhausting searching, and having to learn how to animate a simple sprite for the 100th time, I hope I might found I more specific, and better explained answer to my problem.

       

      I'm trying to make a flash game, of course, and I want my main Player sprite to be able to play multiple animations based on specific input. So, a running right animation, a running left animation, a jump animation, and an attack animation.

       

      At the moment, the most I can seem to achieve is to create a single timeline, with a default frame in the exact middle. Then when player holds left, it plays the previous frame, or scrolls backwards through the timeline. When the Right key is held, it plays forward from the default middle.

       

      It's ugly and extremely limited. I've tried using the gotoAndStop() and gotoAndPlay() methods, but because the statement checking for the key being pressed is constantly being checked, it will stay on the frame chosen for those methods, rather than move forward along the time line.

       

      I would greatly appreciate a better method for this, or a more specific tutorial to achieve the goal i'm looking for.

       

      I've seen mention of the attachMovie() method, but I can not find an understandable explanation of how to properly use it in the way I desire.

       

       

      essentially, the sprite will have the default standing frame while no keys are pressed. Then, if the right key is down, it plays the running right animation. When the left key is down, it plays the running left animation. When the jump key is pressed, it plays the jump animation. And when the attack key is pressed, it plays the attack animation.

       

       

      I hope that's enough information and that it's understandable, if not, let me know what more you need to know and I'll do my best to explain it more.

        • 1. Re: Multiple Animations for a single MovieClip sprite
          DazFaz Level 1

          You can do this a number of ways but I will try to explain the what I think is the easiest.

           

          Step 1

          Draw a box on the stage

          Step 2

          convert this into a movieclip (F8), name this myCharacter (or anything you want really), then press ok. Now select this movieClip and in the properties dialogue box, type "box", again, without the quotes. Then press enter.

          Step 3

          Double click this new movieClip (this should take you into this movieClip timeline)

          Step 4

          Now press F6, 3 times. This wil give you 3 additional key frames on this timeline. You should now have 4 key frames.

          |Step 5

          Select key frame 1 on this timeline and press F8. Type into the diag box "standing", without the quotes. Then select the Movie Clip radio button, if it is not already selected.

          Step 6


          Step 12

          Make sure  your library is in view, if not Ctrl+L. You should see the movement clips you created, running_right, running_left, etc. Double Click any one of these and add the animation your want in these movs.

           

          There we go, simples.....Test you animation and see how you are doing.

          Select key frame 2 on this timeline and press F8. Type into the diag box "running_right", without the quotes. Then select the Movie Clip radio button, if it is not already selected.

          Step 7

          Select key frame 3 on this timeline and press F8. Type into the diag box "running_left", without the quotes. Then select the Movie Clip radio button, if it is not already selected.

          Step 8

          Select key frame 4 on this timeline and press F8. Type into the diag box "jumping", without the quotes. Then select the Movie Clip radio button, if it is not already selected.

           

          Great, once you have done this, these new movieClips should now have appeared in your library (press Ctrl+L if you cannot see your library)

           

          Ok then you have just created your movement MovieClip. You now need to get back to the main timeline. You can just keep on clicking the stage to get back to this location. Once there you need to select the box you have just created and name this "box" for the time being.

           

          Ok then a little bit of programming now.

           

          Step 9

          Create a new layer in the timeline and name it scripts.

           

          Step 10

          Then select this layer and press F9 on your keyboard. THis should bring up the scripting pane for this frame.

           

          Step 11

          Type in the following code

           

          box.stop();// when you run this animation, this command will stop your box from doing anything
          var keyBoardListener:Object = new Object();// Creates a new Object for the keyboard presses
          keyBoardListener.onKeyDown = function() {
          if (Key.isDown(Key.LEFT)) {// runnning LEFT action
            _root.box.gotoAndStop(3);// Frame where the running right animation is
          } else if (Key.isDown(Key.RIGHT)) {// running RIGHT action
            _root.box.gotoAndStop(2);// Frame where the running right animation is
          } else if (Key.isDown(Key.UP)) {// JUMPING action
            _root.box.gotoAndStop(4);// Frame where the JUMPING animation is
          }
          };
          keyBoardListener.onKeyUp = function() {
          _root.box.gotoAndStop(1);// When the keys are released, this action takes your animation back to frame 1, where your character is just standing still.
          };

          Key.addListener(keyBoardListener);// this assigns the listener to your key press detection Object.

           

          Step 12

          Edit the action movs within your library by double clicking each one and adding movement to each. Then test your animation.