2 Replies Latest reply on Jun 23, 2010 2:54 AM by Haru_Lance

    Animating sprites (need help).


      I need help to animate a sprite so that when I push a direction key the sprite will animate when it moves and will return to the starting position when it stops moving.

        • 1. Re: Animating sprites (need help).
          clbeech Level 3
          well ok, there are going to be several factors you'll need to decide as to 'how' it animates. additionally you'll either want to store the 'home' position of the sprite, or use 'hard' coordinates that are 'known'. since you have not provided quite enough detail as to 'how' or what direction you would like your sprite to move, by what keystroke or by what increment, I'll just provide a very basic script here to get you going.

          commonly we use an onEnterFrame method to provide an animation trigger like the one your suggesting here, which will 'read' the currently depressed key and continue to update the position until the key is released. once released however, it's a little unclear as to what you want to have happen since you've said, "...return to the starting position when it stops moving" - which doesn't quite make sense. so I'll assume that you are intending that the sprite animate back to toward the starting position, if a key is not in use.

          a script to do so would look something like the following:

          • 2. Re: Animating sprites (need help).

            I'd suggest creating a movieclip, and creating an animation inside it. Click on the first frame of your new animation line, and give it a frame name, for our explanation, i'll use "Standing".


            double click the Flash area so it returns to the main frame, and it should show your movieclip sprite in it's initial frame.


            Click on your sprite and you can use script like this to control it a little better.



            onClipEvent (enterFrame) {



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





            If it is something like a run animation, or something you need to loop several times with out copy pasting frames and having it end on you if it runs out before you release the key. Find the frame with the animation where the run would start, give it a frame name, something like "Run1". Then go to the last frame of your run animation, and go to Actions for that frame.








            If that made sense and you did it properly, the sprite will play through each frame, looping appropriately, and then return to the initial frame when the Right key is released.