Ready to watch this entire course?
Become a member and get unlimited access to the entire skills library of over 4,987 courses, including more Video and personalized recommendations.Start Your Free Trial Now
- View Offline
Another really handy expression is the ability to loop an animation. I want to clean up my display by selecting Close All from the Comp panel and open up 04-LoopOut*starter. Hopefully, the Rotation keyframes have already been exposed for this layer, and I'm going to turn off the background for now and just remove the distraction. Now what we have is a simple two-keyframe animation-- I'll press 0 to RAM Preview--of this watch piece rotating in one direction. Let's say you want that to repeat, rocking back and forth.
Numbers can exist on their own in expressions, but when you use words as parameters in expressions, you need to surround them in quotes. Close parentheses, press Enter, and now let's RAM Preview this. And you'll see that my watch piece is now seamlessly repeating its animation over and over again, ping-ponging back and forth between its two keyframed values. The loop expressions are something that's much easier to understand if you make a trip into the Graph Editor, so let's go ahead and open that up. And you need to do two things to really work with expressions in a Graph Editor.
One is there's this little button here called Post-Expression Graph. This is how you get to see graphs in a Graph Editor or motion paths in the Comp panel after the expression has been applied. And as soon as I enable it, you'll see what is going on. The dotted line is a result of the expression continuing on this animation. The second thing I like to do is go down to the graph type options and choose Show Expression Editor. This will now show you any expressions attached to the selected property right here in the Graph Editor.
Once you're in this view, it's really easy to see what's going on. For example, if I go ahead and select this second keyframe for rotation and drag it earlier in time--I'll press the Shift key to make sure I keep it as original value-- you'll see that I merely oscillate more quickly. And I'll RAM Preview and there is the new animation. If I select both of the keyframes and pick them up and move them higher, I'm just going to change the value range used for the rotation. RAM Preview, now you'll see an offset in one direction.
I'm going to undo that. Also, if I move the keyframes later in time by holding Shift key again to keep the values the same, you'll see that loopOut only affects what happens after your keyframes. It does not affect what happens before the keyframes. Now if you do want something loop into an animation, rather than loop out of your animation, you just need to change this from loopOut to loopIn, and now you see that you have the opposite behavior. I'll press 0 to RAM Preview, and that's the result.
I'm going to undo back to my loopOut with the keyframes starting at the very start of the composition. You have loop types other than pingpong. For example, I'm going to double-click to select the word pingpong, make sure I leave the quotes, and type the word cycle. This says rather than go back and forth between the keyframes, repeat the keyframes. Press Enter in numeric keypad to accept the expression, and you can already see from the Expression graph exactly what's going on in this animation.
You almost don't need to RAM Preview it, but let's do that anyway. You see we keep snapping back to initial position. Another interesting variation is offset. This says rather than repeating the exact values you're at before, add or subtract those keyframes to where you left off. Now if that wasn't clear, let me just press Enter again, and now you'll see that the values keep descending. After it's gone to a negative extreme, it's going to use that as the new starting point to rock a little bit further.
I'll press 0 in numeric keypad. You'll see where it rocks and it continues on from word stop rather than rocking back, or starting over. So offset is another interesting loop option, and I'm going to go ahead and go back to pingpong, since that was a fun animation. There are a few other variations on the looping expressions. For example, if I was to place another keyframe, say, partway through this animation, I'm going to go ahead and click on my Add or remove keyframe switch so I've another keyframe right there.
Let's say, rather than loop that entire animation, I want to loop just these two keyframes. Well, you can do that. You need to go down into your expression, go after the word pingpong, type a comma to indicate that you're about to add another parameter onto the expression, and add a number. Now in typical programmer logic, if you want to repeat two keyframes, you need to enter 1. That says use one more keyframes than the last one for loopOut or the first one for loopIn.
Press Enter and you can see from the graph what's going on: we're now ping-ponging back and forth just between these two keyframes. If I was to change this to 2, that says reach two more keyframes from my out point. Now you see we have the full animation again. But just so you can see what's going on visually, I'll type 1, Enter, 0 to RAM Preview, you can see where it just gets stuck over in this part of the animation. There is another interesting option, particularly if you have a complex animation and just want to repeat the very end movement.
In addition to looping based on keyframes, you can also loop based on time. Instead of the expression loopOut, you need to type loopOutDuration. And again, the first letter is capitalized, except for the very first word of your expression--no spaces in between. You saw pingpong, cycle, and offset for your options of how to loop, but now rather than the number of keyframes, you set the length of time. Let's say that we want to loop the last 3/10ths of a second of this animation.
Press Enter and now you see that we're just going to go back to this point in time and then keep repeating that. RAM Preview. If I want to loop a half second, I'll enter 0.5. Now you see I'm repeating more of my animation. And just to give an idea of the sort of fun you can have with this animation, go ahead and open up 04-loopOut_final from the Comps_Finished folder, and you'll see we've created a number of little watch pieces with some variations on how they're looping.
I'll press 0 to RAM Preview. This will take a little while to queue up because there are so many layers going on here. And there is also some other fun expressions we have used, like using expressions to keep the drop shadow constantly falling off to the lower right of these objects. You'll see where we're doing things like offsets here, different speeds. You can go ahead and study this just as a reminder of what variations on loop expression can do for you. Now all that said, neither the linear interpolation nor the loop expression are our favorites. Our favorite expression of all time is wiggle, and that's what we'll cover in the next movie.
The After Effects Apprentice videos on lynda.com were created by Trish and Chris Meyer and are designed to be used on their own and as a companion to their book After Effects Apprentice. We are honored to host these tutorials in the lynda.com Online Training Library®.
- Creating and managing expressions
- Linking together different parameters
- Randomizing a layer's movement
- Looping an animation
- Controlling multiple layers from a single source