Applying loop expressions
Video: Applying loop expressionsNow, there's an expression that's really useful to every animator in nearly every situation called the Loop Expression. And that's what we're going to have a look at here. If you want to follow along, you can open up the Expressions and Scripting Project, and that's in the Expressions and Scripting folder. Now, we're going to start with this one here, 058 dog walk cycle. And I'm going to open that, and you'll see that I have this layer in here. And if I preview that, you'll notice I have a dog walk cycle, but it only lasts for a few frames.
Viewers: in countries Watching now:
In her career as an animator, Angie Taylor has developed some powerful techniques for creating quick but compelling 2D animation, and in this workshop she shares those secrets with you. Learn how to import layered files and paths from Adobe Illustrator into After Effects and how to animate flat vector artwork in both 2D and 3D space, and explore options for outputting your animations. The videos are short, focused, and solution-oriented, and all the project files are included so you can follow along as you go.
- Best practices for importing source files
- Sorting and interpreting footage
- Animating using traditional layer-style animation
- Creating a grouping structure for body parts
- Animating with the Puppet tool
- Creating stop-frame-style animation
- Setting up control layers
- Animating using time remapping
- Exporting files for Flash
- Making movies via the Render Queue
Applying loop expressions
Now, there's an expression that's really useful to every animator in nearly every situation called the Loop Expression. And that's what we're going to have a look at here. If you want to follow along, you can open up the Expressions and Scripting Project, and that's in the Expressions and Scripting folder. Now, we're going to start with this one here, 058 dog walk cycle. And I'm going to open that, and you'll see that I have this layer in here. And if I preview that, you'll notice I have a dog walk cycle, but it only lasts for a few frames.
If we have a, step through frame by frame, you'll see we've got a few frames of it, and then it stops. Now, what I want to do is I want to loop this so that he continues walking, okay? And this is a composition, a nested composition. If it was a piece of footage, or a sequence, I could loop it by going into the Interpret Footage dialog box, and choosing Looping Options in there. But this is a nested comp. If I double-click it, you'll see all it is is a series of frames stacked on top of each other.
So, how do I loop it? Well, I've applied Time Remapping to this. And I apply Time Remapping, going to Layer > Time > Enable Time Remapping. And we'll have a look more at Time Remapping a little later. And basically, what time remapping has done is it's added keyframes for the active frames of my animation. So basically, that's going from the beginning to the end of the animation. Now, when you first apply Time Remapping, it will be trimmed up like this. So, I've just trimmed out the end to continue all the way to the end. Now, the last frame is black so I don't really want that frame included. So, the key to making this work is move one frame back from the last keyframe, zoom in to the timeline, and add a keyframe there. So, if you want to add a keyframe of the existing time, you click on the Add or Remove Keyframe at Current Time button.
And then, if we delete this keyframe, the black one, we'll now hold on that frame all the way to the end. So basically, what we've got is we've got the moving frames between here and here, and then we've got static frame all the way to there. So basically, what we want to do is we want to repeat the values between these two frames over and over again to create a walk cycle. And to do that, I'm going to Alt click on Stop Watch and I'm going to add the loop expression, which is in the Property menu.
So if we choose Loop Out, Type Cycle, okay? Now, there's an extra thing in there called Num Keyframes. We don't need that so I'm going to delete the comma and the num keyframes equals zero, and basically we've done it. If I preview that, basically what it's doing is it's looping that section over and over again using a cycle loop. And a cycle loop just keeps going forwards. Now, you'll notice there's another black frame in there. If we go back to the beginning, you'll notice there was a black frame at the beginning.
So again, step forward by one frame, zoom in, add a keyframe there, and then remove that last keyframe at the beginning. And now, we should have a perfect looping dog walk with no black frames in between. Okay, and if we have a look at that property graph by clicking the Graph button for the expression and the Graph Editor, we can see what cycle it does. It just keeps going forwards, keeps going forwards. Okay, so that's a cycle loop allowing us to loop an animation forever, basically.
So, the second loop expression we're going to have a look at is Ping Pong. So, I want you to open up 05B Stick Man Ping Pong. And in here, we have a layer which is basically doing half a walk cycle. So, in order to make him walk, I'm going to have to go forwards, backwards, forwards, backwards as opposed to the last one, which just wanted to keep going forwards. Now, I've applied Time Remapping and I'm going to stretch the layer out to fill the whole gyration, and then I can add an expression to the Time Remap property.
And again, click on my Expression Language, choose Property > Loop Out. And this time, I'm going to edit it and instead of cycle, we're going to type Ping Pong, and the Ping Pong loop will go forwards, backwards, forwards, backwards, and it should create the effect we want for this walk cycle. And if I preview that, see, we now have our character walking forwards, backwards, forwards, backwards. Again, if you get the black frame in there, you just need to go to your last frame, zoom in, move one frame before, add the keyframe there, and then just delete that black keyframe.
And now, we should have our character walking for as long as we want, going backwards, forwards, backwards, forwards. And let's have a look at the Expression Graph. And if I zoom out, you'll see basically, it's moving forwards, backwards, forwards to create that kind of loop, which is a ping pong loop. Now, the third and final looping expression. If you open up 05C Stick Man Continue, is the continue expression. Now, here we have a character getting bigger over time.
And what I want to do is make him walk across the screen. So, what I'm going to do is use motion sketch. I'm going to click on the character. I'm going to get my pen and my Wacom tablet because that's the best thing to use for capturing motion and applying it to your characters. Click on the Start Capture button, and now all the movement that I make with my pen on my tablet will be captured and applied to the character. But sometimes, you'll find that you accidentally let go at one point, or something goes wrong with it, and I'm going to show you how the loop expression can help with that.
So, here we go. He's walking towards the screen. And then, I run out of time or I run out of space on my Wacom tablet. And I've got a nice movement. But as I said, I ran out of time. So, what do I do? Well, I could capture the whole thing again. Or if I just want him to continue walking in that direction at the same speed, and what I can do is apply the continue loop expression. So, Alt click on the Stopwatch, go down to the Property section of the Expression Language menu, and loop out again. And this time, what we're going to do is type in, continue. Okay, so make sure I spell it correctly, continue.
Spelling is not by big strong point. And then, delete the text that we don't need. And now, if we preview that, we should see he walks along, and then he continues moving at the same speed in the same direction until he goes off screen. So, if you've done a motion path and it's slightly short and you just want to keep someone going at the same speed, then you can use continue expression to do that. Okay, so if we have to look at the end composition, here we see it again.
Okay, I have't quite got my timing right by that one, but you get the idea of how that works. So, those are the three looping expressions, cycle, ping pong, and continue.
There are currently no FAQs about 2D Character Animation with After Effects.