Making things look better
We're done with new topics for this chapter. Let's work on our animation to make it presentable. In this lesson we'll wrap-up the topic of adding animations into timelines.
Video Transcript
00:00Happy, we are not with the current animation status, but you are the one that is learning
00:06how to animate, so I'm going to leave it up to you to really make a wonderful animation.
00:10But in the process, we'll just see how to play around and configure a little bit more,
00:13have a little bit of fun with our animation, try to get it to a better shape.
00:17But I do expect you at this stage with the level of training that you have already,
00:21which is really high.
00:24To come up with your own interpretation, upload it onto your site, send us a link in the
00:28comments section, I would love to see your interpretation, create something amazing,
00:32surprise me, surprise you, surprise us.
00:35Alright, so let's see what I'm doing, not very exciting, because I want you to
00:39excite me.
00:41This chapter, let's figure out a more rational interpretation of the animations we
00:46have here, and a rational interpretation would probably be seeing the images one
00:50after each other instead of not seeing them really at all.
00:55So what I want to do is I'm going to have the first image appear, stay there for a
00:58second, maybe fade out, have the next image come in, and so on and so forth.
01:04So like that, we could have this kind of progression where we could see what the
01:08doggy is doing, which would make a lot more sense.
01:11Alright, so let's do that.
01:13So let's go ahead and get that animation going on.
01:16So the first step is I'm going to just, for the sake of clarity here, what I want
01:21to do is I'm going to just start with by commenting out all the different
01:25animations that we're doing to our elements.
01:27So I'm just going to go ahead here and just comment them all out.
01:32Now that I have all these animations commented out, and I know that initially
01:36when my first item comes in, I'm sending its opacity to be invisible, which is
01:41good, because we're going to have all these items being added in before all
01:44animations take place.
01:46So the next thing that I want to do is literally start using my timeline,
01:50and I'll start with just fading the element in.
01:53So let's go ahead and just fade it in using the to command, and I'm just going
01:57to go ahead to to this, and I'll just set the opacity to one after a one.
02:03Let's give it a one second animation and have it to go to opacity of one,
02:09and I'm also going to make sure that I'm going to have here a delay of,
02:13let's say, two seconds plus equals two.
02:19Now, if I go ahead and run this, let's see if we're getting what we want,
02:23and if not, we'll continue and tinker with it.
02:27So I'd go ahead.
02:28First of all, we have that initial load time, that initial animation that's
02:31going on, then we got to that 10, and then we're not seeing anything.
02:36So, oh, and then suddenly they all appear.
02:39Oh, no, actually, yeah, here we go.
02:41One, two, three, four.
02:47So this is a little bit too slow, so I'm going to go ahead here and just
02:50add here, let's give it a delay of one second for each, and we'll have it
02:55animated in a half a second.
02:58And let me go ahead and above here where we initially configured these
03:02animations, I really want to solve this thing.
03:04So first of all, I don't need this countdown, or maybe I do need the
03:08countdown, but even if I do have the countdown, I don't want to affect
03:12the timeline at all.
03:13So I'm going to go ahead here and just wrap this on H1 done, not send to it
03:20any third parameter of the position.
03:22I don't want to play around with the position at all.
03:25Beyond that, I also want to make this animation a lot faster.
03:29And to do that, well, really what I want to do, when I'm thinking about this,
03:33I could leave this, but what I really want to do is I actually want this
03:36initial animation to probably come in a little bit sooner.
03:40I'm not going to solve that because I'm just going to waste your time
03:42if I do that.
03:43But really what I would want is for these initial animations, this first
03:47animation specifically, to not start in right now, but start in much
03:52earlier.
03:53So we'll solve that in a later chapter if we're still doing this, but
03:56I'll definitely show you how could you do that.
03:59And we're going to do that using two timelines, but we're going to
04:01look at that when we work with two timelines in parallel.
04:05Right now, we're working only with one.
04:07So this should be good for me, and I think this should be fast
04:11enough, so we'll be able to both see the images as they're coming
04:14in, but also not be too intrusive and too weird.
04:18But before we wrap this up, what I really want to do after all these
04:22animations are complete is I want to start having them animate into
04:26their place.
04:26So beyond having these items go the way that they're going, what
04:31would be really nice is if once animation is complete, then we go
04:35to that initial state that we had there.
04:37And that's exactly what we're going to do to wrap up this lesson.
04:40And to be able to do that, I'm going to need to keep a reference to
04:44each item.
04:46So as images are being added, what I'm going to do is I could create
04:49here just in my geeky element there.
04:52I'll just create here a geek to geek to dot a images, and I'm just
05:02going to set the default to be nothing.
05:05And the next thing that I want to do is I want to basically
05:07just append into this a images each time.
05:10I have an image that is ready.
05:12So I'm going to go ahead into my images on image loaded.
05:15It's ready.
05:16It's loaded and I'm just going to go ahead here and just add it
05:19into that array because what I really want to do is I want to
05:22have access to it so I could then start manipulating it back
05:26to whatever animation we had initially.
05:28So now that we're storing all this stuff, what I really
05:31want is also some sort of a callback that will be called
05:34when the animation completes.
05:36So to do that, I'm going to go into our timeline and I'm going
05:40to add here another property.
05:42So I'm just going to go here and add an on complete.
05:46Complete and I'm going to call on animation complete.
05:56Alright, so on let's call it on TL complete for timeline
06:00on TL complete and I'm just going to scroll all the way
06:03down here somewhere and I'll just create that function
06:10and that should be triggered when our animation completes.
06:12I'm just going to give you a little console log to make
06:15sure that it's called.
06:17Hello, and I could go ahead here and click on refresh.
06:26And when the last animation completes, then I should get
06:29it in our console, which is going to take us a little while
06:33here.
06:35And in the meantime as it's going on, so we don't have
06:38to watch it all over again.
06:40Let's talk about what we want to do.
06:42What literally what I want to do is I want to basically
06:44start adding more animations into it, but now that I have
06:47an array of my items, I could use one of those stagger
06:50functions and what I really want to do is I want to stagger
06:53too, but the problem with the stagger function is if
06:56you recall, we had the same basic object that we were
07:00sending them to.
07:02So what I'm going to have to do is basically loop through
07:05and create the destinations that I want them to go to save
07:09them into our array and then add them using the add method
07:12that we've discovered earlier.
07:14So if we go back into our application now that we're
07:16done talking about that, we should see that hello in
07:18our complete beautiful.
07:21So now in our complete, what I really want to do is
07:23I basically want to recreate most of this logic here
07:26really.
07:27So I'm going to literally I'll just grab this because
07:29we're not using this anymore inside of here.
07:32And what I'm going to do is basically go into my
07:35on image complete create here a loop.
07:37So let me say first of all a variable variable for
07:40I and I could go ahead here in my eye.
07:44Well, why am I doing an eye?
07:46What was I trying to do?
07:47Let's just do the loop for var I equals zero.
07:51I is smaller than what I smaller than our a images
07:55length is a lot of back and forth a images dot length.
08:05And we want to bump our eye eye eye each time by one
08:11and we want to create a lot of tweens.
08:14So I'm going to go ahead here and just create a variable
08:16called T for tween AT.
08:19I'll make it as a new array and I'm going to go to
08:24AT and push inside of it tweens.
08:27So let me just create also a variable tween.
08:29So it's so it'll be a little bit more visually comfortable.
08:33So I'll just call this T for tweens and let's start away.
08:37So basically what I need is I basically need this from two.
08:40I just need the two really but or maybe I do need the
08:43from two because I want to make sure that the mask
08:46initially takes the full scope of our view.
08:50So if I go ahead here and I'm just going to bump this
08:53here just so I could visually look at it.
08:55But really what I want to do is I want to create a new
08:57tween. So I'm going to go to tween light and we want
09:02to do a two or a from two in this case.
09:06And what are we animating?
09:08We're going to animate the specific image that we're in
09:10right now. That's our first parameter eye eye.
09:16Second parameter is going to be how long do we want
09:19it to animate?
09:20I'm going to give it one second as well. Third parameter
09:23that we want to give here is our where are we?
09:27Where are we?
09:28Where are we?
09:28Where are we?
09:29Third parameter is actually what is our clip itself.
09:32Okay, so let me just delete all this stuff that we
09:34don't need from here.
09:35So it'll be easier to look at it.
09:38So we have here the from position where it's starting
09:40from and is this information good enough that we have
09:44here?
09:44Do we want to start it from this position?
09:47No.
09:47What we really want to start from and if we recall,
09:50let me just bring this up so we could visualize it.
09:53What we really wear where we want to start it from
09:59is this type of a clip.
10:02So I'm just going to put it here.
10:03So we have a visual reference.
10:05So we said a rectangle our top position.
10:08We want it to be at zero.
10:09So that's that that's okay.
10:12We have zero our right position.
10:15We want it to be zero as well.
10:18We want to stop start from the top.
10:20Oh actually we want our left to be zero not our top.
10:23So we want to make sure then let me just delete
10:24this whole thing and we'll write it instead of getting
10:26confused.
10:27So first thing is zero pixels is for our top.
10:30Beautiful.
10:31Our left our right.
10:32We don't know yet our bottom.
10:34We don't know yet our left.
10:35We know it's zero pixels now for the right.
10:39We want it to be basically the total width of our
10:42application and we should have that variable here.
10:45So that's our width.
10:46I wanted to basically take the whole span because it
10:49is completely visible visible visible.
10:53All right, so I'm going to put that that is our second
10:56parameter which is our right which is basically our
10:59width.
11:00Okay, so that's good.
11:02Px for that and last parameter is our bottom and
11:06our bottom.
11:07Do we have a stored reference to it?
11:09Yes, we have our height.
11:10So I'm going to go ahead here and reference to our
11:13height really quickly and put our height right inside
11:17here.
11:19Make sure that I'm adding plus on each side and ending
11:22it with a PX.
11:23Okay, so that is our starting position.
11:25Basically a clip of the whole stage area.
11:30The next part is we want to clip it to where it's
11:32supposed to go and this is where it's supposed to
11:34go.
11:35The only thing that's missing is that that right
11:38and left that we had going on right here.
11:40So I'm just going to cut it because we're well,
11:42let me copy it because you might want to use it if
11:45you're going to go back and look at the source
11:46files.
11:47So I'm going to go right back in here and I'll
11:49just create these variables outside of here and just
11:53go and create the values and left.
11:55What will the left actually be?
11:57Let's see.
12:00So the left will be the index but instead of index
12:03we're just going to put the actual I position
12:05that we're in right now,
12:06which will basically be just replace that with I
12:12and for our left position for our okay,
12:20we're going to take that value right here.
12:22Let me just delete the value putting in on the
12:24top here and I'm just going to make sure that
12:26I'm not referring to my index but instead of
12:28that I'm referring to the I itself because
12:30we're literally doing them all at the same time.
12:33Now we've done quite a lot.
12:35So although we're not done with our animation,
12:36I'm going to go back to see are we even close
12:39to what we want to get and the values here
12:41should basically be the same.
12:43Nothing here on the bottom part of the clip
12:45should change because we have the from we have
12:47the to all that's left for me to do is to
12:49basically just close up this this function
12:52and make sure that I'm actually closing it.
12:55Let me see if I'm oh I close it already here.
12:57So let me open that up right there and here
12:58we're closing it.
12:59So we have your first parameter of the from object
13:03the to object.
13:04We're going to save this go back into our
13:06application click on refresh.
13:08It's going to take us a little bit of time,
13:09but that's what we got to do to get this sorted.
13:13You know what and if already we are now.
13:16All right, let's wait it.
13:17Let's wait it out and we are almost done.
13:28Doggy is eating and the elements animate
13:31into their position.
13:31I could see that I'm off one.
13:33So the reason why I'm off one is because I started
13:36at position zero and that is why I'm off one.
13:39So I'll just go ahead here and just do I plus one.
13:41But more or less, I'm quite happy with this
13:43animation. The only thing I might want to do
13:46is actually added into my timeline.
13:49So to add it into my timeline after the loop
13:51is done and we pushed each each tween into
13:54that array.
13:55So let me go into the 80 and just push that
13:58tween into it.
13:59So we have access to it.
14:02I literally could go ahead and just and then do
14:05add if I wanted to basically do a tween add.
14:08So I could go ahead and just add here the add.
14:13tween well into our timeline.
14:19Where are we in our timeline geek timeline?
14:22And I'm not going to go ahead and do the whole
14:24thing because we're quite happy with the way
14:25it is already at this stage.
14:27I'm just going to add those tweens into it.
14:29Literally just sending that AT that array of
14:32tweens and as we said we have those extra
14:34parameters and I'm going to give you to figure
14:37those out and figure out how do you want
14:39them to animate through because we're done
14:41with this chapter and I think we're in a much
14:43better shape than we were when we started
14:45from when we started and in the next chapter
14:48we're going to move into a new layer of
14:51working with timeline.
14:52So far we were working with timelines mainly
14:55controlling time itself but not really
14:58manipulating things once they were created.
15:01From the next chapter we're going to go back
15:03into seeing how do we manipulate data after
15:05it's already been added in.
15:08And by the way we have your bug and our bug
15:11that's going on here is an endless loop
15:14and this endless loop is happening because
15:16each round that we're going each time that
15:19the on complete happens it happens again
15:22and then another tween happens and another
15:24tween happens and another tween happens.
15:26So what we were going to have to do is
15:27basically delete that initial on complete
15:30after the first time it's called and we
15:32already saw how to do that.
15:33All we have to do is go to our time and
15:36delete that event once it's done.
15:39So I'm going to go to my geek to to my
15:41timeline to my vars object as we've seen
15:44before and call that on complete.
15:47And that's it once I've done that and I
15:49saved that I could go back into my
15:50application click on refresh and this
15:53time around when I refresh it and the
15:56animation will go through won't play
15:57it through because it's going to take
15:59too long then our animation will complete
16:02and we won't have that error.
16:03I urge you suggest you encourage you to
16:06come up with your own interpretation of
16:07how do you want this animation to take
16:09place.
16:10All right.
16:10See you in the next lecture.
16:12Second well actually next chapter and
16:15in the next chapter by the way is we're
16:17going to walk away from just adding
16:19things into the timeline and start
16:21actually controlling the timeline itself.
16:23It's going to be a very exciting
16:24chapter.
16:26It's going to be a very exciting
16:27chapter.
