02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Defining tween position in TimelineLite

In the last lesson, we added three tweens into a timeline. When we did that, we discovered a few things that didn't work well. The first; our delays were irrelevant, as items were stacked one after each other. We solved the problem by removing the delays. Our second problem is a bit more challenging, as we want our animations to overlap. In this lecture we're going to learn to control the position of tweens in TimelineLite.

Video Transcript

00:00In our last lecture, we added our items in to a timeline,
00:05but once we added them into a timeline,
00:07everything kind of got messed up
00:09and we really want to have a little bit more control
00:12over where their position will be in the timeline.
00:15And that's exactly what we're going to be talking about
00:18in the next lecture.
00:19And really we're talking about adding a delay
00:22or subtracting a delay, enabling you to control
00:25when will the next item that is being animated start.
00:29Will it start immediately after or will it start
00:31in some sort of a delay of a second later,
00:34a second before and so on and so forth.
00:35By the end of this lesson, you will know how to position
00:38your items that you're adding using the add function
00:41into the specific spot you want them to be in.
00:45So we're going to stick to the timeline add function
00:48for a bit because it has a few more properties
00:50and we're going to break them down into separate videos.
00:54But once we're done with the add command,
00:55many of the other commands in the timeline
00:59will be very familiar and with it very easy.
01:03All right, so the first thing I want to do
01:04is I want to talk about the second parameter
01:06of the add function.
01:07I'm just going to create here just a timeline light
01:12to add and we have here the first parameter is the object.
01:17The second parameter is position.
01:19And we're going to look at other parameters real soon.
01:21Now the position enables me to change those default scenarios.
01:25So in this case, I have first the fade in,
01:28which I'm fine with that.
01:29I want to start with fade in,
01:30but really what I want to happen is I want this animation
01:33to take place only a second into our timeline.
01:36And by adding here basically a comma
01:39and adding the basically, I usually add a string really,
01:43but I'm adding one because adding one
01:46will be a hard coded value saying,
01:48I want to start this in position one second
01:51of our timeline, a very hard coded value,
01:54which is completely fine if I'm doing it
01:56for the first first item.
01:57And what's that that is going to do
01:59is it's going to push all the animations by one second
02:02because the timeline is sequence
02:04and they're connected to each other.
02:07And in other words, if I go back into my application
02:09and click on refresh,
02:10we should have a full one second of nothing
02:12before our animation continues.
02:14And it doesn't affect our other elements
02:16that are being animated.
02:17So I literally could say, Hey, I want here to have,
02:20I want to start this animation in position three
02:23in our timeline.
02:24In other words, in second three.
02:25Now, again, we talked about in a previous video
02:27that there's frames and there's seconds.
02:31Let's assume everything is seconds
02:32just to keep our mind clear and easy.
02:36So this would basically say that three seconds in
02:38we're going to start our first animation.
02:40And because everything is sequenced in,
02:43this will start after it, and this will start after it.
02:46Now the power of this versus adding a delay
02:49is that you really want to put all your controls
02:51in your timeline if you could.
02:52Now it would work in the exact same way
02:55technically, if I would go inside here
02:58and let me just show it to you first that it's working.
03:00So now we'll have your three seconds, one, two, three,
03:03and only then our animation will begin.
03:06Now I could very easily auto position this in this position.
03:11So let me just put it right here,
03:13put your delay, add your three seconds.
03:15If I run it, it's going to look exactly the same way.
03:18It's going to do the exact same thing.
03:20And you might ask yourself, so what's the difference?
03:23Why don't I just add that delay, right?
03:25Right where it was, which is a wonderful question.
03:27And that is the question that I'm asking you.
03:29So click on the pause button even before you press play
03:32because I'm going to give you the answer right away.
03:34Because I want to see if you know
03:35how to figure this one out.
03:37All right, so I'm giving you a second to click on the pause
03:40assuming you did already, let's answer the question.
03:42Okay, so the big difference here,
03:45and if we take it into our timeline here for a second
03:47in our flash element here,
03:49when we added our first item,
03:51we're really adding it in position one.
03:54Now, if I say to my timeline,
03:56if I say to my application position this in second three,
04:00literally what I'm doing is I'm pushing all of this
04:03to three seconds.
04:04So if this is 15 is every second here, 30, 45,
04:08I'm pushing it all forward.
04:10Do I have my animation in position zero?
04:12No, my animation is starting in position 45.
04:15All I did was tell it a start the animation from here.
04:18Contrary to that, if I put a delay
04:20in the animation itself,
04:22I'm literally, the item is actually added exactly here
04:26and exactly in the beginning here,
04:29but because the item has extra body, you would say,
04:35then the animation would take place
04:36basically all the way here.
04:38Or in other words, if I just copy this
04:39just for the sakes of illustration, copy this layer,
04:44and it would basically start from here.
04:46Nothing would be going on in those three seconds,
04:48but the item itself is sitting
04:50in this spot in the timeline.
04:51It is an important differentiation.
04:54Contrary to only adding the item
04:57in a specific spot in our timeline.
05:00So that is the big difference between
05:02putting it into the delay itself
05:03versus putting it into the global control,
05:05which is our second parameter of our position,
05:08which is what we wanna do when we're working
05:10with timelines in general.
05:12So I'll wanna set that property and set that position.
05:16Now, we saw that in the first item
05:18and we said we could put a hard coded value
05:20if we wanted to.
05:21But really the default, what is the default?
05:23The default is, if I just could do this here for a second,
05:26the default is plus equals zero,
05:28which basically means whatever your timeline is right now,
05:31add nothing to it and add it to that spot.
05:34That's the default.
05:36Now I could put a value that is hard coded
05:38and hard code a position in the timeline
05:41where I wanna put it in very easily.
05:43I could do it in seconds, I could do it in frames,
05:45depending on how am I thinking about things.
05:47Obviously the more things you're adding in,
05:49it makes it a lot easier to work in frames
05:51and then you wanna control globally
05:53how many seconds will those frames be.
05:55That could be very convenient.
05:57But in our case, we're gonna stick to seconds.
06:00So now that we set that time,
06:02let's say I wanted to set it to one second.
06:03What happens in our case?
06:05So first of all, we have this animation happening
06:07right after that second is over.
06:09I don't, right after that fade in completes
06:12and that seems about right.
06:13I don't want it to move while the fade is happening.
06:16But on the other hand,
06:17I don't want this to begin for another,
06:19let's say half a seconds.
06:21So the way I solve that is I send my second parameter
06:24and I could say plus equals zero dot five,
06:27plus zero, zero dot five or dot five.
06:30I'm basically telling it,
06:31just add another half a second into the position itself.
06:35Don't position it right in the end of this item.
06:38Add another half a second in between this animation
06:41and animation, meaning that the pan itself
06:43will take place a little bit after this pan
06:46has started.
06:48But obviously we want this pan to be longer.
06:50So let me set this to be four seconds.
06:52So literally this will basically start
06:55just before this item completes.
06:57But really in my case, what I would really want to happen
07:00is the exact opposite, but let's see that it works.
07:04So literally what we should see here right now
07:05is we have here the fade happening separately.
07:08The animation here happening separately,
07:11excuse me, a delay of one second and then the pan.
07:14Not exactly what we wanted.
07:17We wanted an opposite effect,
07:18so I'll go here and just set here minus
07:20and I could literally say, okay,
07:21I want you to happen three seconds earlier,
07:25literally saying a second after this item begins.
07:28So if I just go ahead here and click on refresh,
07:30we're gonna see that now the fade in is happening separately
07:34but the zoom in and the pan is happening at the same time
07:37minus that one second that it was going on on its own.
07:41So that's it about this part.
07:43In the next lesson, what we're gonna do
07:45before we even continue playing
07:46with other properties of the add function,
07:50what I want to do is I want to go back to our on update
07:53and figure out where do we put this now.
07:55And that's exactly what we're gonna do in the next lesson
07:58because we want to get these toggling
08:01and all these extra elements working again
08:03because now they're not working anymore
08:05since we got rid of those variables
08:07and we turned off the listeners to them.
08:09But that's exactly what we're gonna do
08:10in the next lesson.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!