Aligning tweens in TimelineLite
So far when we were adding tweens into a TimelineLite, we assumed that every tween is automatically added to the end of the timeline. In this lesson, we will add more than one tween at a time. As we do so, we will learn to respect delays and how to sequence tweens. By the end of this lesson, you'll know all of the strategies involved with aligning tweens in TimelineLite.
Video Transcript
00:00As promised, we're back into the add method.
00:03We said that there are four parameters, or maybe we didn't,
00:06but I'm saying now there are four parameters.
00:08We met already two of them,
00:09which one of them was the object that we're animating,
00:11and the second thing was the position of that object.
00:15Now we're gonna see how can we add more than one object
00:17at a time as we explore the third parameter,
00:20which is the alignment, basically helping us position
00:25and define how will the element be added into our timeline.
00:29And this is only relevant when we're adding
00:31more than one animation at a time.
00:33So let's see an add method.
00:35And to take advantage of it,
00:37we're gonna have to do a few small changes.
00:39For one, and I'm just gonna get rid of
00:42a little bit of the extra stuff we don't need here.
00:45For one is we're gonna have to pass first
00:47our variables into an array.
00:49And the reason is we could add our items as an array
00:53and not only as directly items.
00:55Now that's gonna change our configuration here,
00:58but that's fine.
00:59So we're gonna just create our A tweens,
01:01and I'm just gonna go ahead and just send in
01:04as our array values all those tweens.
01:07So literally I'm just gonna create an array,
01:10and I'm just gonna go ahead first item,
01:13and second item, and last but not least, our third item.
01:22And you can probably see already how powerful this could be
01:25if you have a lot of animations going on at the same time,
01:28which is definitely something we're gonna see
01:29very, very soon in a later chapter.
01:32For now, let's just get really familiar
01:34with the timeline.
01:36All right, so I'm commenting out all those ads,
01:38and instead of that, I'm just gonna create one ad
01:40and literally just add all our tweens together.
01:43And that's it.
01:45Once I add all those tweens together,
01:46if I just go ahead and save this,
01:48I could literally just send an array,
01:50and by sending an array, I'm basically,
01:51I could control all the animations at the same time.
01:55Now obviously, we're gonna be back to the same problem
01:57that we had earlier where our animations
02:00are being set, are being added in,
02:04and we're not basically controlling
02:06how we want them to be added in,
02:08because we're adding them in, and if you notice this,
02:10you'll see that everything is happening at the same time.
02:13You see that all the animations are basically one
02:15after each other happening in the exact same duration,
02:19exact same time.
02:20So there is no staggeration here at all
02:22when I'm adding my animations in this level here by default
02:26when I just add all those animations
02:29without that control of that extra time
02:31of a second here, a second there,
02:33a delay, there's no delays here.
02:35So literally, if I just set this to be four seconds,
02:38and this four seconds, and this four seconds,
02:40look what will happen.
02:41Literally, what will happen is our animation,
02:44the fade in, the delay, the zoom in, the pan,
02:48they're all happening in the exact same amount of time.
02:51They're basically stacked one on top of each other
02:54as if they were one item.
02:56Now it doesn't have to be that way.
02:58We could then, we could control it
03:00through the third parameter.
03:02We saw that our first parameter was the item itself
03:05or which was a tween or a cluster of tweens.
03:09In our case, we sent three tweens.
03:11We said the second is that position in time.
03:13So in our case, we do wanna start a second in.
03:16So I literally, just by setting this,
03:18I could have that small delay that I really wanted.
03:21And now I'll have a one second delay
03:22before all three animations are gonna happen
03:25at the same time.
03:27Literally, what that means in a visual perspective
03:29is if this was animation number one,
03:33and this was animation number two,
03:35and they were starting at the same time,
03:37and let me just delete this here.
03:40Let me just find the delete button.
03:42Oopsie.
03:44Let me just get rid of that.
03:46Remove tween.
03:49Ah, nevermind.
03:50Let me just duplicate this
03:51because the point is this, right?
03:53So basically, we have all the three animations,
03:55and if I go ahead, if we have your three animations,
03:58all the three animations
03:59are basically being stacked one on top of each other,
04:01coming in the exact same spot.
04:03Now, if any one of them had a delay
04:05or a different length or whatever it might be, that's fine.
04:07They would just go in whatever direction that they would be,
04:10but they would all start in the exact same time.
04:13Now, if I wanted to have better control over it,
04:16that's exactly where the third parameter comes in.
04:19So while we had the position itself,
04:21so if this wasn't the beginning,
04:23like we said before, we could do plus equals one,
04:25saying there'll be a second
04:26after whatever the position we were in,
04:28because we could have a few ads, right?
04:30And then we could add a few things at the same time.
04:33And the next property is the align property,
04:35which could get one of three different values.
04:39The first one is normal.
04:42And normal basically is putting them all in together,
04:46but respecting any internal delays that they have.
04:49So in this case, this is the default.
04:51So I'm not really doing anything.
04:53This is the exact same default
04:55that we would have originally.
04:57The only difference here,
04:58and if I go ahead here,
04:59and I'm just gonna make this one second really,
05:02and I could go into this item,
05:03and I'm gonna say, hey, to you,
05:05I wanna add a delay of one second,
05:09and I'm gonna have it for three seconds
05:11like we had originally.
05:13What I'm doing here is all three of them are added in,
05:16and the delay itself is being respected.
05:19That's what the third parameter says,
05:21and that is the default.
05:22So if I go ahead here and just click on refresh,
05:25we're gonna see the first item fades in,
05:27the second item joins in,
05:29and basically we have that delay.
05:30So if you notice it just one more time,
05:32we'll see that they're all working in sync with each other
05:37the way we would want them to work,
05:39and the delay itself is being honored here.
05:42The next thing, and if it's not very obvious,
05:44let me make it even more obvious,
05:46I'll put here a delay of three seconds.
05:48That way it'll be very visually noticeable
05:50that the zoom in itself only happens for one second.
05:57But we're noticing here that,
06:02we're noticing here that even though we're doing this,
06:05we could see that the zoom in is actually happening,
06:07and the delay itself is not exactly honored
06:11from what we can see.
06:13Because I'm not really seeing that really delay,
06:15even though technically in the documentation
06:17of tween light and of the timeline light,
06:20it says that it will align and will honor the delays.
06:24That's what the normal should be.
06:26But if I just, let me just delete this,
06:28let's see how it works if we don't even say anything,
06:31and we just send in nothing,
06:33which should be the normal configuration.
06:36So let me give it one more try here.
06:38But no, I'm not seeing a big,
06:39I'm not seeing any difference,
06:40so let's move on to the actual different parameters
06:43and see them in action.
06:45So the second one is the start.
06:48Now the start one basically aligns
06:50at the start of the tween and it ignores any delays.
06:53So it will basically ignore anything that we have here,
06:55which is really what we saw also with the normal right now.
06:59So there might be a small bug in the version
07:01that I'm running in, which is kind of cool.
07:03All right, so we could see that the normal
07:05isn't 100% functional right now,
07:07so I'm just gonna send that as a bug report
07:08to the guys at Green Sock,
07:10and hopefully we could tweak this video at a later date
07:13where the normal will work.
07:14All right, and last but not least is sequence,
07:17which is really where things get interesting.
07:20Seq,
07:22Seq,
07:23wah.
07:26And if we add the item with a sequence,
07:29the sequence itself basically makes sure
07:31that they align one after each other like the default is.
07:35So if we go ahead here and just click on refresh here,
07:38now we should get that the item first fades in,
07:41then it zooms in, then it pans.
07:44And that's exactly what we thought it would do,
07:46and it does ignore the delays as well.
07:49So the only thing right now
07:50that doesn't seem to be working the way we would expect it
07:53is actually the normal one,
07:55which I'm kind of surprised that it's not working
07:57the way we would expect it to, but that's the status.
08:00But technically, the way it should have worked,
08:03it should have respected the delays
08:05that we had inside of our element.
08:07So this delay right here,
08:10oh, you know, I'm talking about their bug,
08:12but it's absolutely my bug,
08:14because I'm actually putting the delay inside of the CSS,
08:17which is something that I should have thought
08:19that maybe I'm doing something wrong.
08:20And these are one of the hardest bugs to find out.
08:24I was just trying to do one last check
08:25to see if I had any typos,
08:27and then I realized that my delay itself
08:29is not inside of the right place.
08:31It's inside of the CSS object.
08:33I do this mistake so often.
08:35So let's give it just one more run
08:36now that we actually have the delay,
08:38and we should be getting the animation
08:40exactly the way it should be,
08:41and it definitely was my bug.
08:44And there we go, that's exactly what we expected it to do
08:47when we were doing it in the normal.
08:50So go ahead and play around with normal,
08:53with start, with sequence.
09:02And as we said, the normal,
09:04basically the normal is that it respects the delays,
09:11it honors them, but they add,
09:13all the items are added at the same time,
09:15and the delays are respected.
09:17Start ignores the delays and adds them all at the same time,
09:21while sequence puts them one after each other,
09:23just like our add function would have,
09:26as if we added completely separate add functions
09:28to our element, if we just set the normal or not,
09:31or haven't set anything there at all.
09:34All right, so this is a little bit long
09:35and a little bit confusing as my fault
09:37because I put the delay in the wrong spot, my bug,
09:40but boy is that great training
09:43if you've realized it and noticed it.
09:45And these are exactly, you know,
09:46I love these type of errors and these type of bugs,
09:48and I do my best not to hide them
09:50as long as I don't go too crazy.
09:52I thought they made a bug, but obviously they didn't.
09:55I'm the one that made a bug.
09:56All right, so now that we got that sorted up,
09:58we'll see you in the next lecture
09:59where we'll still be in the add function,
10:02and we're getting very, very close
10:03to the end of this chapter,
10:05and we're gonna wrap up this chapter
10:07with a conversation about the last parameter
10:09of the add function.
