The expression language provides two convenient ways to loop a sequence of keyframes: loopOut() and loopIn().
Suppose you keyframed a short animation and you want
that sequence to repeat continuously. Simply add this expression to the
keyframed property
and your animation will loop for the duration of the comp (Figure 1).
Tip
A small glitch in the cycle version of loopOut()
drops the first keyframe from each of the loops. If you want the frame
with the first keyframe to be included, add a duplicate of the first
keyframe one frame beyond the last keyframe. |
There are three other variations of loopOut(), as well:
loopOut("pingpong") Runs your animation alternately forward, then backward.
loopOut("continue")
Extrapolates the animation beyond the last keyframe, so the value of
the property keeps moving at the same rate (and in the same direction,
if you’re animating a spatial property such as Position) as the last
keyframe. This can be useful, for example, if you’re tracking an object
that has moved offscreen and you want After Effects to extrapolate where
it would be if it kept moving at the same speed and in the same
direction.
loopOut("offset") Works similarly to "cycle"
except that instead of returning to the value of the first keyframe,
each loop of the animation is offset by an amount equal to the value at
the end of the previous loop. This produces a cumulative or stair-step
effect.
loopIn() operates the same way as loopOut(), except that the looping occurs before the first keyframe instead of after the last keyframe. Both loopIn() and loopOut()
will accept a second, optional parameter that specifies how many
keyframes to loop. Actually, it’s easier to think of it as how many
keyframed segments to loop. For loopOut() the segments are counted from the last keyframe toward the layer’s In point. For loopIn()
the segments are counted from the first keyframe toward the layer’s Out
point. If you leave this parameter out (or specify it as 0), all
keyframes are looped. For example, this variation loops the segment
bounded by the last and next-to-last keyframes:
Two variations on the expressions—loopOutDuration() and loopInDuration()—enable
you to specify the time (in seconds) as the second parameter instead of
the number of keyframed segments to be looped. For loopOutDuration(), the time is measured from the last keyframe toward the layer’s In point. For loopInDuration(),
the time is measured from the first keyframe toward the layer’s Out
point. For example, this expression loops the two-second interval prior
to the last keyframe:
loopOutDuration("cycle",2)
If you leave out the second parameter (or specify it
as 0), the entire interval between the layer’s In point and the last
keyframe will be looped for loopOutDuration(). For loopInDuration(), the interval from the first keyframe to the Out point will be looped.