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

Staggering our animations with two timelines

In our attempts to create a reusable animation, a logical outlet for us is to break each of these animation components into their own timeline. In this lesson, we will create a staggering animation and break apart our animations into two separate timelines.

Video Transcript

00:00All right, so let's get back into finding the voice of this animation.
00:02And just as a quick recap, we created that break in plug in
00:06tween, which basically tweens in our the break plug in tween
00:11in that it basically creates that tween.
00:14It adds a tween.
00:15It returns a tween light to our array that we're pushing into our a tween,
00:19which by the way, I don't know why I called this a tween as if I knew
00:22that I'm going to use tweens here.
00:24So let me just let's call this a just a for alpha,
00:28you know, just in case that because it could have used for anything
00:31this alpha, it could be text fields, it could be tweens,
00:33it could be anything that this plug in returns to us.
00:36OK, so we have our a we are mean, which basically means
00:41that if I come here and I.
00:43If I come here and I create a new a tweens array,
00:47I'm going to get all those tweens into an array.
00:49And now it's time for us to create that timeline light instance
00:54tween lights or actually it's timeline light, timeline light.
00:59I'll create a new instance of that.
01:03And when I create a new instance, instead of just creating it and moving on,
01:06I'm going to send to those initializations variables.
01:10I'm going to send inside into the tweens property, my a tweens.
01:14Now, nothing is going to happen as soon as I do this.
01:16If I run my application again and fix this error.
01:19So first of all, that a tween doesn't exist anymore.
01:23So just delete that, run it one more time and let's run it again.
01:28And we'll see that our animations are literally getting in exactly
01:31the way we wanted them to get in.
01:33Nothing changed. Nothing is different.
01:35So let's make it different now that our tweens are actually staggered
01:39and are inside of our timeline light.
01:41They're initially running all at the same time
01:43because we put them in at the same time.
01:46What we could do next is literally go to the tweens and say, hey,
01:49take all these tweens that we're putting inside of these tweens
01:52and just add a delay between them by calling not the delay property
01:55that like like we're used to inside of tweens.
01:58Instead of that, we call the property Stagger.
02:01And in the Stagger property, you could put any value in seconds
02:04or frames if you set it as frames.
02:06We're going to assume that you all are working in seconds.
02:09But if you do prefer working in frames, you would put your frames instead.
02:13If you set the configuration of frames, when does that get into that?
02:16Let's just put your a half a second and let's see what would happen
02:19if we put here a delay of a half a second between the animations
02:23and I run it one more time.
02:24Now we're going to get our initial animation to stagger in.
02:27So if we run it one more time really quickly,
02:30you'll see that our initial animation is staggering in.
02:34Beautiful.
02:34But we really want our bottom animation to stagger as well.
02:37So literally, we could just copy the exact same thing
02:40that we've done up here by basically taking our eight tweens
02:44and then creating a new timeline light.
02:46So I could just go ahead here and I'll just call this timeline two
02:49just for the sake of timeline two, just for the sake of this animation.
02:54And well, we don't need a new array.
02:56We could send the same array because we're just overriding that array.
02:59Or, you know, let's call it a tweens two just to be clear
03:02that it's a completely different tween.
03:04So I'm going to call this a tweens two.
03:05And I'm just going to send a tweens two into my tweens.
03:08And again, literally, that's all I had to do.
03:11And I could remain it in the same exact stagger that was there before.
03:15And run it.
03:16Now, I could, if I wanted to go and say,
03:18hey, for my tweens are on the bottom here, let's add also a delay.
03:23So one one way for me to do that is literally just to come here
03:27and just type the property delay and I'll put here a 10 second delay.
03:30And if I put here a 10 second delay, then the initial timeline
03:33won't start until 10 seconds.
03:35Oh, 10 seconds in, which is going to be quite a while.
03:39So we're not going to wait it out.
03:41So let's put here instead of that, let's put here three seconds.
03:43We'll be able to see it in action a little bit faster.
03:45Now, that's one way of dealing with this type of
03:51scenario where three seconds in, then the bottom part is going to start as well.
03:55What if we just wanted them to be one after each other?
03:59Or what if we wanted to create some sort of a stagger effect
04:02using more timelines?
04:03And although in this case, it's probably not necessary.
04:06But imagine that we have an endless amount of lines.
04:08What if instead of doing one liners, we were doing here 50 lines.
04:11We wouldn't create a separate delay for each one
04:14and create them differently.
04:16We probably would want to find some sort of a logical
04:19scenario where we could integrate what we need.
04:22So I'm just going to comment that out.
04:24And I just want to show you one more possibility of option
04:28that you could actually do.
04:30And what you could do is literally create a new timeline
04:33animation time.
04:36Line light animation, new time.
04:40Time line.
04:42Time light light.
04:44And literally this time around, instead of sending in tweens,
04:48I could go to my tweens property and instead of that,
04:51send an array of our timeline one and our timeline two,
04:55which is T L.
04:58And T L two.
05:00And I could put here also a stagger effect,
05:03which the stagger effect would only stagger
05:06literally the these two items I have here,
05:10but it could have been an endless amount of items, really.
05:13And if I run this now,
05:14I'm going to have basically a main timeline
05:16that has two timelines as its children.
05:18And instead of using a delay, I'm using a stagger.
05:21This is just so you can see the different variations
05:23of how powerful this animation library really is.
05:27And if I run this one more time,
05:29we should see that our animation starts in and then three seconds in.
05:32The bottom animation resumes and adds.
05:34Now, obviously, we have here a small issue
05:36that we don't want all these characters to be visible initially.
05:39So we could just go here really quickly to our break in tween in
05:44and we could or throw our copy really far out of the stage
05:48by making sure that our Y position will be at stage stage height,
05:52let's say, plus five hundred.
05:55So we're making sure it's really out there
05:57and it's far away from so it's not visible.
05:59That's one option.
06:02Another option, which is not necessarily the prettiest option,
06:05and it really just depends on the type of animation you want to come in.
06:08For example, you might want you might like this animation,
06:10but maybe you want the copy to come from the left.
06:12So you can literally define that and decide, hey, OK, let me go here
06:16and I'm going to put this into the stage stage. With.
06:21Literally moving a copy out of the stage, further out of the stage, making it.
06:26Oh, I did it with the Y property, Y property,
06:29and I wanted to do that to the X property.
06:32So let me just check, change it to the X and literally these small stuff
06:36are really big because they're going to create that big change in your animation
06:40just by setting where that initial position is.
06:43Or you could have just said the and by the way,
06:47just so you noticed, our X zero zero is right here.
06:49So when I'm saying the stage width, it's a lot out of our stage.
06:52So if I wanted, I could have made it even half that amount.
06:55And I think we should have still been more or less out of the screen.
06:59Maybe maybe you would see half of the character.
07:02So if you wanted it to be closer, you could set it to be
07:04in a closer position as well.
07:06But really, this is really a game of you twinking, figuring out.
07:10Or again, you could have started it with an alpha of zero, which I personally
07:14don't like the effect as much.
07:15But let me show you the effect of the alpha.
07:17I personally don't really like animating things in an alpha,
07:20usually if they're moving also because they usually create a bit of
07:24boring animation, to be honest.
07:26It's very like where it reminds me of,
07:30you know, those built in animations that exist inside of Office.
07:34But if you like this type of animation,
07:36it's really just a matter of taste.
07:38I personally prefer just trying to push things out of the stage
07:41whenever I can to a nice spot out of the stage.
07:44And once I find that right sweet spot, it could be also in a negative.
07:47So, you know, like you could always play around and try to figure out
07:50what the what type of and all these stuff are going to create
07:53massive different differences.
07:54So again, we could see that this is still in the stage
07:57because our character, we need also to take into consideration
08:01consideration the size of our character.
08:03So I could literally maybe take it two thirds out of the stage,
08:07basically by duplicating, by dividing by three and duplicating by two.
08:10That should probably for sure leave our content all out.
08:14But in our case, it didn't because so let's just let's just the whole
08:18let's make it a minus a whole stage worth making sure it's really out
08:22and it's not going to be visible.
08:24So those are the games that you could do with those episodes.
08:27And and I will wrap it up with again, we're just going back and saying
08:31so the way we made sure that we had that stagger, we could have
08:34or in their second timeline to create a delay or we could have added another timeline.
08:38Now, I want to talk about a couple of more stuff.
08:41So before we continue or right after this, we'll talk.
08:45Well, yeah, let's do that in the next lecture.
08:47And in our next lecture, I want to basically find out
08:49when are all of our animations have completed, or I want to know
08:52when a certain animation completes.
08:55So we're going to see how do we deal with that?
08:57How do we add a callback that would call
09:00basically when our animations are complete.

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!