Join Angie Taylor for an in-depth discussion in this video Creating looping animations, part of After Effects Expressions: Getting Started.
- View Offline
Okay, after the math chapter, we need a bit of light relief. So we're going to have a look at the expression language, which you can access in the Expression Language menu. There's also a lot of help in the After Effects help. So make sure you have a look under Expression Reference to get help with expressions if you get stuck. Now, we're going to start by having a look at looping. And here, we have some position key frames.
You'll see there I've got this, creating a kind of loopy animation. And you can see the motion path there if I select that motion path. What I want to do is I want to get this to loop, okay, so it continues playing throughout the whole duration. So, what I'm going to do is I'm going to add an expression, so Alt-click on the stopwatch. And then I'm going to go into my expression language menu. Now we've already had a little delve into here, but notice that there are categories. So there are different categories to help you figure out where you should find things.
Now, if it's something to do with a property, you'd go down to the Property section. And in here, there's lots of useful things. We're going to have a look at some of them. We've already had a look at some of them, like Value and Value At Time. We're also going to have a look at some of the other ones in the future. But the one that we're going to look at to start with, is this one. So Loop Out, okay, we're going to choose that. So choose Loop Out, and it will write an expression for you. If we click away from that and preview it, you'll see now we get a looping animation.
But notice when it gets to the end of the loop it goes back to the beginning. And that's because the default loop type is a cycle loop. So let's have a look at how this is done. It's saying loop out, and then in parentheses, type equals cycle, number of key frames equals 0. Okay, so basically, the number of key frames but we don't need to use at the moment, we're just going to delete that. The only bit that we're really using at the moment is cycle. So we can actually remove that. And the word cycle is what's making it loop.
The type of loop. So, if we have a look at our post expression graph, that will help us understand what's happening. And, if we change our graph type to our value graph, you'll notice what's happening. So, it's going through, the process of the animation then it's jumping back to the beginning and starting again. And that's what it's doing for us, okay? We may want to have a different kind of loop. For example, let's switch off the post expression graph on this one. And open up this. If I select and double hit the E key to open up it's expression, I can click on the Post Expression graph button for this, and you'll see that this is a different kind of loop.
It's going forwards, backwards, forwards, backwards. And if we switch on this layer. So if I solo it, and just, let's switch off the other one. And preview it. So RAM preview. You'll see it's going forwards, and then going backwards. So it's, this is what's called a ping-pong loop. So it makes it go forwards, and then play backwards. So to and fro if you like. And if we click off the Graph Editor button, then we can have a look at the expression. And you'll see it's the same as this one, except the loop type is ping-pong.
Now there's one other loop type that is very useful indeed. If we double-hit the E key, we'll see we've got one called, Continue. And Continue is extremely useful. Let's solo that and switch off the previous layer. And first of all preview it. And we'll see what happens. You'll see it continues on the loop, and then goes off in the direction it was moving at. So basically what happens with this one, if we go to the graph editor, and let's switch off our Post Expression Graph button for that layer and switch this one on, you'll see what happens if I just adjust the graph height.
So lets just make this a little bit bigger. Okay, you can see basically it's doing the same animation, it's just on a smaller scale because of the graph. And then, it's continuing at the speed and the direction that it was moving before that ended. And that's really useful. So if you're creating some kind of movement, and you want the object just to continue moving in the same direction and speed, then Continue loop will do that. It's a really useful expression.
So you got three different types of loop, switch 'em all on at the same time. Switch off our graph editor button, and we can see them all playing, going completely loopy. So that's the loop expression.
- What are expressions?
- Creating and applying expressions
- Linking expressions to layers with the pick whip
- Simplifying expressions with variables
- Creating looping animations
- Randomizing values
- Converting expressions to keyframes
- Creating keyframes from audio with expressions
- Controlling 2D effects in 3D space
- Converting color from RGB to HLS
- Formatting strings and text