Looping Animations


Maybe the coolest feature unique to expressions (one that users often wish was built into the After Effects user interface) is the ability to loop a set of keyframes. It's so easy to learn and powerful, however, that once you understand it, you might even like it.

What's up with spaces? Typing "x * x" or "x*x" in an expression has the same result. In fact, you can put as many spaces as you want between the operator (*) and its operands (x). It's purely a matter of what you prefer to look at. Where you get into trouble is in adding spaces where they don't belong, such as in the middle of a name; valueX is not the same as value X. If there are spaces in a name you pickwhip, the name appears in parentheses, for example:

 motionTracker ("Tracker 1") ("Track Point 1"). 


Much of the time, you just can replace your source expression text with one of the default loop expressions and be done. These are found in the Property submenu of the Expressions menu (Figure 10.9).

Figure 10.9. Try not to be overwhelmed. The expressions menu is a well organized cheat sheet of After Effects keywords. Once you understand a little bit about how it's organized and where the most useful items are located, you can open this with confidence. The Property submenu, shown here, might be the one you visit most often because it contains several essential functions.


The loop effects have two arguments, the settings found in parentheses after the command. The first one is mandatory; you have to specify the type of loop you're requesting by choosing one of the three loop types. The second is optional and, in some cases, unavailable.

Expressions Menu and Hierarchy

The Expressions menu is a bit overwhelming to the uninitiatednearly two dozen submenus with several entries each. How do you know where to find anything?

Two significant observations can make this menu less daunting:

  • Most of the entries don't do anything, technically speaking, other than point to a value that you can sample.

  • The menus are organized hierarchically, from most global to most local. So at the top is the Global submenu, which has shortcuts to areas of After Effects that are available on the broadest or most global level. At the other end of the menu are Property and Key, which work on an individual property of an individual effect applied to an individual layer in an individual comp. In other words, these are the most nested expressions.

So don't worry, it's not as gnarly as you might think.


I'll start with a basic example and then detail out the various permutations, and then show you a specific problem that looping solves.

I'll use the example of a blinking light that is animated via keyframes to its Opacity control. To blink, these keyframes, which turn it on and off, must repeat. Begin by creating one cycle of this animation, start to finish. For example, it could be a burst of light (100% Opacity) followed by a hold and a decay at or near the beginning of the composition or wherever you want it to begin (Figure 10.10).

Figure 10.10. Opacity of this light decays over ten frames, with an ease added out of the first frame, followed by a hold between frame 10 and 20, at which point you are in need of a loop.


Now set an expression for Opacity, and with the default expression still highlighted, choose

 loopOut(type = "cycle", numKeyframes = 0)  

Press the Enter key or click outside the text area. Your keyframes now loop.

Specifically, the loop acts as if the first keyframe followed one frame after the last keyframe; this is always how it works. So, if for timing purposes you want a pause at the end, you build that into your keyframe pattern. Figure 10.11 shows the animation with a hold at 0 Opacity added at the end.

Figure 10.11. A loop has been added to the animation in Figure 10.10. The default expression (chosen from the menu in the instructions) would work, but unnecessary arguments have been removed here to shorten it (see the sidebar, "Extraneous Verbiage").


Extraneous Verbiage

How can two expressions

 loopOut(type = "cycle", numKeyframes = 0) loopOut("cycle") 

achieve the exact same result? Here's a quick explanation: Expressions don't do a lot of hand-holding in terms of telling you what to enter and where, but the default settings sometimes come with extra keywords that are totally optional; their only purpose is to remind you what the values are for. In the case of this example, not only are the keywords "type =" and "numKeyframes =" optional, but the whole second argument will default to 0 if it's missing.

Now how the heck would you know this? After a while, you start to anticipate it because it's somewhat standard. As you begin, however, the only way to know it is to read it in a book like this one. Sad but true.


Before looking at the other loops available, check out the other arguments you can set for this expression. For example, numKeyframes specifies how many keyframes before the final one are used in the loop; set to the default of 0, it uses all keyframes. You can get rid of this argument altogether in such a case (see the sidebar, "Extraneous Verbiage"); in fact, the expression would work the same if it read loopOut("cycle"). Set numKeyframes to a value of 2 and it uses the last three keyframes for the loop, ignoring the first hold keyframe (Figure 10.12).

Figure 10.12. The hold keyframe, added at the beginning, is ignored because of the numKeyframes = 2 argument, which limits the loop to the two keyframes preceding the final one (which, as you may have noticed, the loop ignores, using it only as a placeholder for the first keyframe of a new loop).


The more useful argument is probably the first one, because it changes the fundamental type of loop, and there are three possible arguments:

 loopOut("cycle") loopOut("pingpong") loopOut("continue") 

You've seen the results of cycle, and I will cover continue in the next section. The pingpong option is like cycle except that it alternates looping the keyframes forward, then backward, then forward to ping-pong them back and forth (Figure 10.13).

Figure 10.13. The eminently useful pingpong loop is applied here.


Extending a Motion Track

Chapter 8 contains tips for continuing a motion track using a simple loop expression. What if your footage needs both a loopIn("continue") and a loopOut("continue") to extrapolate the track not only beyond the end but before the beginning of the keyframe data?

You could do this with conditionals, telling expressions to execute loopIn before a certain frame and loopOut after a certain frame, but a simpler way if you're just getting comfortable with expressions would be to split the layer at the beginning or end of the keyframe data and apply loopIn to the first portion and loopOut to the second portion.

Remember that this trick only works if the first (loopIn) or final (loopOut) two frames accurately represent a steady state at which the layer should continue animating. It only typically holds up for a few frames.


As for the other loop types available, loopIn("cycle") works identically to loopOut with one exception; the loop is created prior to the existing keyframes, rather than following. Both loopOutDuration() and loopInDuration() enable you to specify an interval, in seconds, between loops. For example, loopOutDuration("cycle", 2) cycles a loop every two seconds.



Adobe After Effects 6. 5 Studio Techniques
Adobe After Effects 6.5 Studio Techniques
ISBN: 0321316207
EAN: 2147483647
Year: 2006
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net