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

Overwriting animations in TweenLite

Overwriting animations in TweenLite is fundamentally different than overriding animations in TweenNano. While TweenNano isn't built for complex overriding of animations, this is exactly where TweenLite shines. In this lecture, we will see how the overriding mechanism works in TweenLite.

Video Transcript

00:00Hello, and welcome to chapter 3 where we're gonna dive deeper into tween light and not even think about tween nano anymore
00:07Nah, nah, nah, nah, no more
00:10So with that said and after I made a fool out of myself
00:14Let's start about talking about where we left off in chapter 1 when we talked about the override and how it's different in
00:20Tween nano versus tween light and max for that matter now tween light and by default
00:27enables us to create animations and then change our minds whenever we want without having any real damage to us changing our mind because
00:35There isn't and I'm gonna show you that let me just show you an example of that so tween light
00:40And if I'm gonna do a two to our MC logo, and I'm just gonna move it
00:45I'm gonna for a duration of one second. I'm just gonna move it a hundred pixels to the right and
00:52I'm gonna run it just making sure that our that I'm not having any mistakes here
00:57Alright, I have to first say what am I moving so I'm moving the X value and and we're moving we just moved our value
01:03in one second
01:05What would happen if we in the middle of our animation?
01:08I'm just gonna grab this in the middle of our animation. I decide that I want to change my
01:14Let's say I want to change my X position, but this time around I want to subtract 50 from it
01:20Now what I want to do here is I'm gonna add your delay and in this delay
01:24I'm gonna add a delay of 0.2, and I'm gonna make my animation
01:27You know what 0.2 long remember when we were doing the two between nano and chapter one that created an issue where they got confused
01:35And literally what would happen to us if we were using the tween nano which we could probably just show you what would happen instead of saying
01:41Well theoretically what would happen so let me just delete all the extra stuff here, and I'm just gonna import auto tween nano
01:48Just
01:49as a refresher and
01:53I'm gonna take that tween nano, and I'm gonna nano it out
01:56And I'm gonna press play and notice what happening
01:59We sort of that jitter and that jitter that forced us back to that original position because it
02:06Forced us to their original position, but by default when we're using tween light notice what happens as soon as we start
02:15Automatically it overrides that method because it sees that we have a newer more up-to-date command and with that newer up-to-date command
02:23It realizes that now it needs to shift the direction and it does that without having any jitter or janitor
02:29And the reason is is because the default value for tween light is to
02:36Automatically update the variable and only whatever property so for example if we had here the X updating and at the same time
02:43We had also the Y updating it would not stop the Y from animating the Y would continue to animate as you can see
02:50Even though the X has changed, so there's like a partial update
02:54It's not changing the whole gamut of our animation well
02:58And if we go inside of our property and change the default value that was auto to
03:04Overwrite and change it to none for example notice what will happen
03:09Everything is going crazy because it's happening at the same time there is no override
03:13They're just animating it together at the same time creating a less expected a more flickery type of animation
03:20The all option we've seen already we've seen that in the nano option
03:24Which basically overrode our animation and notice how it overrides it?
03:29Immediately when our animation begins our Y now doesn't even get into account
03:34well
03:35One more option is our auto
03:37Which is the default in tween light and by the way doesn't exist at all in tween nano
03:42And you can see that when we do auto
03:44Which is like doing nothing it basically lets it play through without us needing even to change anything
03:50It basically works the way it would default work between not light now all on
03:56Start on the other hand which is very similar the only difference is is that it overrides everything
04:02But only from when the animation begins which means we'll see the Y move a bit
04:06Contrary to what we saw earlier the Y will move 20 pixels and only then it will terminate
04:12If you notice you see that little little jump down of our Y
04:17Let me just make it more extreme
04:19So let me just change our delay to 0.5
04:21So you could see that more more clearly and you can see how the Y is moving as as soon as we override
04:26The Y is terminated as well because we're using all on start
04:31And that's it. Those are the really the the ones you really want to
04:37Do you want to know about there's one more really that you probably could be do you want to be aware of is
04:43pre-existing and pre-existing means that if this animation existed already before then terminate it but
04:50Which means this is pre-existing so we're gonna terminate it
04:55But if we had here another animation going on just about at the same time and this one would have let's see a delay of
05:01one of zero that seven and
05:03It would go for one second and we don't have your any override rule, right?
05:08The override rule will only get rid of this one, but it would not get rid of the next one
05:13So let's see that in motion. Oh
05:16But I didn't really change anything here. Did I so let me change. Oh, I did another 50. So let me change here
05:22Let's do the Y to go plus
05:24Less 150 so we're gonna go up. So we're expecting us to go is for our the Y was going up already
05:30So let's do Y minus we're gonna go down with the Y meaning we're gonna go up
05:34So in the beginning we're going with XY in a linear line
05:38Then after a half a second
05:40we're moving our X and killing the Y position from going down any further and the two milliseconds later
05:46Let's make it three milliseconds later. The Y should start popping back up
05:52you see
05:53So basically the pre-existing doesn't override the next one while on the other hand if I set it to be all on on
06:01Start and I already have something happening later that something that's happening later will not happen
06:08Okay, same is true with all all will terminate everything. All the problem is is that it's gonna be a lot
06:15More boring because this and this would be immediately killed and only this animation will actually
06:20Take place
06:24okay, so basically we
06:31Well, actually when I did the all it actually overrode everything until that moment, but it did not do anything afterwards
06:38So if we see this again, we'll see that the Y is still going up
06:42But we're not seeing the X and going going at all because it's overriding it versus the difference between that and all on
06:49Start notice what happens and all on start all on start
06:54We have both our X and our Y moving
06:56But when we said to set it to all it got rid of the Y completely because the Y was not relevant
07:02It's not in here at all. So we basically got rid of the Y the X
07:06Continued moving but it then stopped as soon as our as our animation began
07:16versus all
07:21Very big difference, right? So so those are the the overrides really do you want to get familiar with it's none
07:28It's all it's out. Oh, it's all on start and it's pre-existing. So those are the five different
07:35Animation styles or animation overrides that you could work with really most of the time
07:40I try to stick to auto because it's the most intuitive
07:43I don't like playing with it too much because it adds complexity and the complexity make your animations complex
07:50You don't have to make those overrides as complex most of the time unless you see that there's some sort of scenario
07:55It's just a lot more useful
07:57So that's it about override that's the last time talking about override
08:00It was a little bit complicated
08:01But just sit down a bit and play around with it and it's gonna look a lot easier once you actually
08:06practice for yourself with the none all
08:09Auto all on start and pre-existing

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!