Introducing the TimelineLite
In the last few chapters, we covered basically everything you can do with standalone animation. That leads us to this chapter.What is it all about? The main topic of this chapter are timelines. Timelines enable us to control a lot of animations at the same time. In this lesson, we will see the timeline for the first time using the TimelineLite class.
Video Transcript
00:00Chapter six. So chapter six is going to be all about that tween timeline or
00:06timeline tween light
00:09So let's get started. What I'm gonna do is I want to start with just showcasing
00:13When does timeline start become really really useful?
00:16So let's start with creating a simple tween light
00:20Animation for that what I'm gonna do is I'm just gonna import the tween light
00:25So I'm just gonna make sure that it's imported and once it's imported what I want to do next
00:30Is I first want to position my logo in a specific spot
00:34So even before I do that what I want to do because I'm going to use the tween quite a lot of times
00:38I want to create a new private function
00:41And I'm gonna call it move logo
00:43And I'm just gonna put here the properties that I want to move in my case
00:46I want to move the X position the Y position
00:50I want to move the scale XY so I'm just gonna call it scale because they're always gonna be the same which is gonna
00:55Be a number and let's let's keep it at that for a second
00:57We'll come back and return more things in a second. All right, so let's create that start basically creating
01:04So I'm gonna call the move logo and the first position I want my logo to be and let's say I want it to be
01:10Let's say initially at position 60 60. I want the scale to be
01:1540% or 0.4
01:18Yeah, and that's about it. Oh, well my problem now is I want to say okay
01:21How long do I want this animation to take well?
01:23I want it to take zero seconds because I want it to be there as soon as we start and I want to also have no delay and
01:30Because in in a second we're gonna have few animations that do have delays. So let's just add those new properties
01:36We said we're gonna add the time. So let's call that Dura for duration
01:39Which is gonna be a number and we're gonna also add the delay which is gonna be a number as well
01:45Perfect. All that's left for us to do is to create that new tween light and send that to command
01:50By the way, the first time around we definitely could have used the set command
01:54But we don't need to because we could use the two and then we don't have to create a unique function
01:59Just for that because then we could reuse our move to logo
02:02And just instead of sending a tie in our time and the duration will just send whatever is there which in our case will
02:07Be zero which will mean do it immediately
02:10Okay
02:10So our target is our MC logo and we want to take it this amount of time the duration based on what we're sending
02:16Which in our case is gonna be zero seconds
02:18And then we want to send our object and our object is gonna have it x position which is gonna value x y
02:25Value y scale x will value scale scale y would value scale as well
02:31And last but not least we want to put your also our delay and in our case
02:36There is no delay, which is fine. You could send the delay zero, which will mean there is no delay
02:40So let's just test it for a second and we should see that our logo is gonna sit snap right into that specific
02:46Spot as soon as we start
02:48Okay, wonderful. Now the next step I want to do is I want to create just a variety of animations
02:53And really what I want to happen is let's say I want I want to have like six animations to my logo and each time
02:59The first animation completes move on to the next one. So to make that happen, let's see the next animation
03:06I'm just gonna randomly say okay. Well, I wanted to move them to a hundred
03:10A hundred and I want the scale to be five and I want it to be a one second animation
03:15And I want to have a delay of one second. Okay, so one second after this we want this to happen
03:21Beautiful, let's move on. Let's continue and then later on I want it to be at 200 and I want it to be
03:26to 200 so we're gonna kind of
03:29Well, let's even do it 250 250 and we want this as the scale now to continue growing
03:35Let's say we wanted to be at zero eight
03:38And we want the animation to take one second, but we want it to continue immediately after this one is done
03:43So that'll be one plus one. So that'll be two seconds. Okay, so step one we got to our position then it took us a second
03:50To get to 100 and 100 and then we aren't waiting at all. We're continuing to 250 and growing our
03:57Scale, so let's continue and now let's say I want to take it to the scale to stage stage
04:03With divided by two I want to go to all the way to the center stage
04:10stage stage height divided by two
04:13let's see and now we want our scale to be at a hundred percent or maybe we want it to be a 1.2 and
04:19We want to basically a little bit bigger. We want this animation to take one second
04:24And again, we want to delay it
04:26So if our delay was at two seconds plus that one there
04:29So we want to have it start after three seconds are over
04:33And let's just do one more or let's do two more animations
04:36I'm just gonna copy this information that I have right here
04:39And what I'm gonna do next is I'm gonna just scale it down to one
04:43So I'm basically animating the X and Y but because I'm not changing anything in them
04:47So they're not gonna really get changed
04:49But we're gonna move down to one and I want that to take all to right after so it's like one after each other
04:55These animations are taking place and last but not least what I want to do is I want to throw our item off
05:01Of the stage, so I'm gonna go ahead and just paste all this here again
05:06This time around I want to delay a five seconds gonna take me one second
05:10I'm gonna keep this exactly where it is
05:11But for the X I'm gonna literally push it out of the stage and how about we make our scale even double up
05:16So it'll be 200% of what it was originally. So let's give it a go what we're expecting it
05:21It's gonna animate and and made animator until it gets out of the stage. I'm sorry for my horse voice
05:26Let's give it a run. Let's see what happens
05:28So our logo should go through basically six small transitions and then it's gonna swing out of our stage a little bit
05:35Leftover here so we could make it a little bit more, but we're not gonna run it again. So so we see
05:41Well, one is great. So we did this animation
05:44But one of the problems that we're gonna have is this is incredibly not legible if I wanted to change something here
05:49So just maybe the duration or my video
05:51Maybe I decided that I want my video to take only zero to seven seconds
05:55And that means for me that I need to now go ahead and change everything here, which is going to be quite hard
06:01And that's exactly where tween
06:04where
06:05Timeline light comes into the picture. It makes life way easier
06:09So what I'm gonna do is I'm gonna show you how it works to do that
06:13What I want to do first is I'm just gonna
06:15Add that in by creating a new tween
06:19A timeline light object. So I'm gonna create a private bar. I'm gonna call it TLL for timeline light. I'm gonna call it
06:28Time line light make sure that it's imported and I'm gonna go right ahead into my constructor and create that object
06:40Beautiful. So I created my new object. What I want to do next is I'm gonna create a new function here
06:46Just to showcase how this basically works and instead of calling it move logo
06:51I'll call it move logo TTL to make sure that we're aware that we're doing it with the tween timeline
06:56now before we continue further what I want to do is I want to make sure that we're gonna call this function instead of our
07:03move logo and
07:05what I'm gonna do next is I'm gonna make sure that I'm gonna actually call inside of my
07:12Logo I'm just gonna call that function by just passing through all the properties in the same way that they came in
07:19All right, so nothing changed yet. If I run it again, I'm gonna see that if I don't have an error here
07:26So let's see what my error is. So I see I then have your little error. Let's see what it is
07:32Access of an undefined property TTL and that is because it's TLL
07:38Save that run it one more time and there we go
07:40And our animation is working exactly the way that we expected it to work now
07:44We didn't yet actually work with our touch timeline light. It's time for us to do that
07:49so to do that what I'm gonna do is I'm gonna go back to my move logo and have it export that tween light and
07:56I'm just gonna make sure that I'm returning it
07:59Because I want this function to return that tween light that was just created
08:04Once I've got that sorted out. I'm gonna show you the next step
08:08So the next step I'm gonna approach my TLL object my time light my timeline light and I'm gonna add a to
08:16Well, I'm gonna add to I'm gonna add well gonna add to it the tween that we've just created
08:23now before I'm gonna play I'm gonna tell you that we're gonna have a problem now the problem is is because this
08:29The animation tool this way when we're working with a timeline
08:33It doesn't expect us really to use the delays although we could but instead of using delays
08:39you'll see that there is a property here that it gives us the option to add basically a
08:46Position and that's exactly what we're gonna look at immediately
08:49But let's first run it and I'll show you what basically would happen and we'll basically what happened
08:53You're gonna see all the animations are a lot slower. So we're not gonna play through it because what's literally happening is
09:00This animation completes only then this animation will move on it sees that it has a delay only now that delay starts
09:07so each cycle
09:09Instead of this going separately on its own
09:12They're inside of a timeline and when they're inside of a timeline if I'm sending it a delay of two seconds
09:17I'm sending it a delay of two seconds after where our current timeline is
09:21registered or in this case that means this would be
09:24Three seconds later or after this animation completes two seconds will be start and only of a delay and only then we would move
09:31On so we must fix this
09:34So to fix this what I'm gonna do is I'm just gonna remove that delay out
09:37We don't want to send a delay or in our case
09:39We'll have to send your zero because we're still working with that delay quantifier
09:44So I'm just gonna make sure that there is no delay inside of our tween and I'm gonna send in the extra
09:49Property and in that extra property remember when we're doing those strings
09:53I could set the string values and and and set if I want to delay
09:57I don't want to delay now in this case if I just send it this way
10:00You'll see that there will be no more delays at all
10:02So it's gonna always continue cycling through and always gonna continue animating one after each other
10:07Even without putting delays which literally is exactly what we expected or and want it to happen
10:13When we were using our delays earlier
10:15so
10:17That is for this example in the next video
10:19We're gonna start talking about how to work with that extra property there
10:23But for that we're gonna just start from scratch here
10:26We'll call it chapter 6a and we'll be in chapter 6a and just start a new animation and we'll look at how do we actually
10:32Work with that extra property. So we'll see you in the next lesson
10:37You
