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

Overriding animations in TweenNano

Overriding animations in TweenNano is the weak spot of the animation class and usually why you would want to work with one of the more advanced classes. Although this topic is a bit complex, it's important to understand why you'd want to upgrade to TweenLite whenever you can. By the end of this lecture, you will know how override methods function and have an understanding of the class limitations.

Video Transcript

00:00So before we wrap up our conversation about Tween.nano
00:03and move on to Tween.light where the heart of our course
00:06will be, I wanted to, again, refresh
00:09what we were talking about.
00:10When we said Tween.nano is really small,
00:12that's its main advantage.
00:15Its biggest disadvantage is that we cannot add plug-ins,
00:18which we're going to see what they are starting
00:20in the next few lessons when we start exploring Tween.light.
00:26And we said it's not compatible with the library
00:29in general.
00:29So it's a standalone application.
00:31And it's intended really for animations
00:33that you're not planning to create a lot of changes
00:36throughout the animation, literally saying
00:39that if it's going in one direction,
00:40we're not expecting it to change suddenly in directions.
00:44We're not expecting for animations
00:45to be adoptable and modifying basins.
00:50That's not the intention of it.
00:52Well, the more Tween.light already enables you
00:54a lot more sophisticated interactions.
00:57Now, I want to talk about the one main difference
00:59and really the only difference that
01:01is very notable besides the fact that it's
01:04a subset with less functions and less properties
01:07and less configurations.
01:10It also has one small difference.
01:12And that comes when you have a clash between two animations.
01:16So let's just see currently our animation.
01:18Currently, we have our text that
01:19fades out and our bunny logo rolling in at the same time.
01:24We don't have any clashes.
01:25How about we add a clash?
01:27So let's start with going again to Tween.nano.
01:30And this time around, I'm going to create a two animation
01:33again to the T names at the same time.
01:35And I'm going to give it a duration of,
01:37let's give it first a duration of one second
01:39and see how it could become invisible, this change.
01:45So let's say I want to create an alpha of one.
01:47And I don't want to change the x or anything like that,
01:49but I want to add a delay.
01:51So this command would only start after a half a second.
01:54And this is a property.
01:55We haven't seen it yet.
01:56We'll see it again in the future.
01:58The property just enables us to delay
02:00the start of this animation.
02:02Now, notice what I've done here.
02:04One is I have here a conflict
02:05between this alpha zero and alpha one.
02:08The reason why I say that there is a conflict
02:10is because it will take me one second
02:13and there's no delay to create this first animation.
02:16But the second animation in the middle through
02:18of the fade out is going to start fading in.
02:21How will Tween.nano deal with that?
02:24So really the way it deals with it
02:27is that there is no override.
02:29So in other words,
02:30the animations will run parallel at the same time.
02:33So what would happen is for the first
02:36it's going to fade out and then fade back in.
02:39But the problem that we have with this
02:42is that the problem that we have with this
02:45which is not very visible to us right now
02:47is if I created the animation that was much smaller.
02:51Let's say I wanted the animation only to be 0.4 seconds.
02:55Notice how this animation would complete
02:57before this animation has finished.
03:00And in that case, if I run my application again,
03:02notice what happens.
03:03It fades in but disappears.
03:05Let's see this once more.
03:08So although it fades in,
03:09the second animation is still continuing
03:12and thus the animation will continue on
03:15from where it left off,
03:16making our alpha turn to zero at the end of it.
03:19What we really want to do is enable us to block that
03:22and say, hey, if we're creating a new animation
03:24we want to overwrite that original animation.
03:27And to do that, we'll type the command overwrite
03:31and we're going to set it to a string value of all.
03:34Now, once we do this and we run the application,
03:36again, you'll see that now it's not going to disappear.
03:39It starts fading out for the first half a second
03:44and then it fades back in in the second half a second.
03:47Okay, so what we learned here is that's how we overwrite.
03:50And now this is really the biggest difference
03:51between Nano by default assumes
03:57that there are no overrides
03:58because it's not expecting to have intricate animations
04:01because we're trying to keep the library
04:02as small as possible.
04:04Although we could override it,
04:05but the problem with the override
04:07that we won't have this type of problem between light
04:10is what would happen if as we're animating the X,
04:13we are also animating the Y.
04:16Now, if we were also animating the Y,
04:18we don't want the animation of the Y to stop.
04:20We want it to complete that one second animation.
04:23So let's say we're animating it
04:25and we want our Y to reach the destination of zero.
04:29Now, let's set up for a second to stop that override
04:32and just see where our Y goes to.
04:35So as our text goes out,
04:36it's going to literally go all the way flush to the top.
04:39So if I'm going to, let's just leave the alpha also
04:41so you could literally see it.
04:42So it's going to go all the way flush to the top,
04:44leaving just a little bit of skin.
04:47So now let's reintroduce our animation.
04:52And this time around,
04:53we're not changing anything in the Y,
04:55but we are making our animation.
04:57How about we make it even a little bit shorter?
04:58We'll do our delay of 0.3 this time
05:02and we're going to make it to 0.3 in length.
05:05That means that this is going to be done
05:0640% before that was done
05:08or a 0.4 seconds before the other one completed.
05:12So if we run this, again, we're going to see a problem.
05:15We're seeing that this override actually
05:18overrode also our Y animation.
05:21So we see that our animation is not moving
05:22in the Y axis at all, which is obviously a problem.
05:29If we were running in a more sophisticated,
05:31more complete animation,
05:33this type of animation wouldn't work.
05:35But between light, there's other options
05:38such as auto, which the default,
05:39which enables us only to override the elements
05:42that are being changed.
05:44Contrarily, when we're working between nano,
05:48we're actually literally overriding the animation
05:50and actually terminating it.
05:52So that is the big difference between the two
05:54because it is a very, very big difference.
05:57So it's not expected for it to have intricate animations
06:01that are overlapping one another.
06:02Contrary to tween light,
06:04where you could have a lot of different animations,
06:06even contradictory animations.
06:08And the last property that was changed
06:11will be the direction of the animation.
06:15So that's it about tween nano.
06:17In the next lesson, we're going to move into tween light
06:20and into chapter two, we could say,
06:22of our training into the world of tween light,
06:25of the tween libraries of GSAP.
06:29And the really fantastic part about this
06:32is from the next lesson,
06:34we're going to be integrated into the real world
06:37of tween light libraries, the tween max libraries,
06:40the GSAP libraries,
06:42which have a lot more interconnectivity
06:45between the different classes.
06:46So see you in the next lesson
06:48where we start exploring the tweens and tween light.

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!