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

Starting to animate with TweenNano

TweenNano is a super-lightweight version of TweenLite and is ideal for situations where you cannot afford the extra 3.1k of TweenLite engine. TweenNano can do everything TweenLite can do with a few limitations. It is recommended that you only use this library in cases where you must meet a low KB (such as banners) and when there isn't a need for interactivity of the animations.

Video Transcript

00:00All right, so we're going to start with chapter one.
00:02And I'm saying chapter one because I'm actually
00:05in the process of creating a course that's
00:06going to be a lot more in-depth about every single aspect
00:11of these tweening libraries.
00:13We've already created four chapters.
00:15And in the next hour, we're going
00:16to try to do together in a kind of quicker pace,
00:19try to go over as much as we could.
00:21So the first thing that I want to do together
00:23is I want to just show you how to work between nano.
00:26We'll just create some simple animations with it.
00:28I imported it already from the com.greensoc.tween.no.
00:34And I've created a chapter one class.
00:36And I've connected it.
00:38Let me make sure that I have.
00:39I connected it to my action script class.
00:43And I like doing this always to just do a little trace here
00:46to always make sure that everything is connected.
00:52Because I hate it when I actually start coding.
00:54And then suddenly it's not working.
00:55So there we go.
00:56So we could see that our check is right there.
00:59We're ready.
00:59Everything is connected.
01:01It's time for me to create a simple, really, really simple
01:03animation with Tween.nano.
01:05What I'm going to do first is what I want to do
01:07is I'm going to take my text here, my text here, which
01:11is a dynamic text field, which is called T names.
01:14And all I'm going to do is I'm going to animate it 30 pixels
01:17to the left or to the right.
01:20Either or.
01:21Doesn't really matter.
01:22All right, so I'm going to go to the Tween.nano.
01:26I'm going to call the to function.
01:28And the to basically says, I want
01:29to take you from where you are to where we want to go.
01:32So the first property that we want to put in
01:34is the actual display object that we want to move.
01:38In our case, it's the T names.
01:40The next property that we want to send in
01:43is how long do we want our animation to take.
01:45So I'm going to give it a second to animate.
01:48And the third less property is an object
01:50that you could create basically dynamically, just
01:54the dynamic object right inside here.
01:56And then you could change and modify
01:58any numeric value of that object.
02:02So for example, if we want to change our x property,
02:04we'll just come here to the x value.
02:07And let's say we want to move it to the position 0.
02:10All I have to do is save it now.
02:11And we could run it.
02:12And we'll see that we'll have a one second animation
02:15where our copy will animate all the way to the one position.
02:18We'll just do it one more time just really quickly.
02:21So we could do this as much properties as we want.
02:25So we could literally, just by sending a dynamic object,
02:29we could literally change whatever we want.
02:32We could change it to the alpha if we want,
02:34send it to 0 as well.
02:35Any numeric value, any numeric value that is really
02:39any numeric value, but any numeric value
02:40that is connected to something you would see,
02:42you could animate.
02:44And that's true to any visual object.
02:47So we just animated three properties, the y and the x.
02:50And they're all going that way and fading out at the same time.
02:55And let's do the same thing for our logo.
03:01So let's animate our logo.
03:02And I'm going to not animate it to, yeah,
03:06let's leave it the way it is.
03:08So it's going to animate out.
03:09And let's create another animation.
03:10But I'm going to use a different property this time.
03:13And this property of the tweenano.
03:15And by the way, these are static functions.
03:17That means you're not instantiating the tweenano
03:20at any state yourself directly.
03:22By the way, behind the scenes is actually
03:24when you create these functions, it
03:26returns to a new tweenano object that
03:29has all the information of that specific animations.
03:31If you want, you could actually store that variable
03:35and save it as a tweenano and store it and get access to it.
03:40And we're going to look at that a little bit later.
03:42So we saw in part one where we were animating
03:46to one of the second most popular ways of animating
03:49with the tweenano, light, and max libraries
03:53is the from.
03:55And the from is kind of cool, a little bit maybe weird
03:58in the beginning, but very, very cool.
03:59Instead of you saying to the animation engine
04:04that you want to take your object from point A to point B,
04:07you're telling the object what point A is.
04:11Contrary to that in this, we're actually
04:13telling him this is point B. Point A was already given
04:16wherever we are right now is point A.
04:18Contrary to that, with the from,
04:19we're basically doing the opposite.
04:21We're telling it we want our animation
04:22to go from whatever properties we're going to send.
04:26And then it's going to go to where it is right now already.
04:29So let's do that.
04:29I'm going to go to my logo itself,
04:31which I already gave it a name, which is called MC logo, which
04:34is that logo right here in the center of our screen.
04:38And let's give it a little shape.
04:42So this time around, as a second property,
04:45we're going to give it one and a half second.
04:48And we're going to play around with the properties.
04:50So let's say we're going to start with an alpha of 0
04:53this time around.
04:54And let's say we will add here, what else?
05:00Well, let's give it a rotation.
05:02How about we'll give it a rotation of 90 degrees.
05:05Now again, don't forget that when we're giving these rotations,
05:08this is the from.
05:09So we're going to start from a rotated position.
05:12And then it's going to unrotate itself back to 0 position
05:15where it was in the beginning.
05:17So if I run this one more time,
05:19we're going to see that our logo is going to kind of do
05:23a 90 degree animation on its spot.
05:26And it will take it a second and a half to do that.
05:30Now, until now, we were, well, until now,
05:34we were basically animating.
05:36But what if, for example, we wanted to move our position.
05:40Let's say, OK, from our y position,
05:42I really want my y position to just go 30.
05:45Or let's say I wanted to go even more than,
05:48let's say I wanted to move 240 pixels
05:53from where it was before.
05:54So basically, I'm saying, if my logo is right here
05:57in the center right now, I want it maybe to start from here
05:59and animate its way in.
06:01Now, the traditional way for me to do it
06:04would probably be just go and set my x value.
06:07And then put here some sort of a hard coded value.
06:10Or I could have gone to my MC logo, type its x position,
06:13and get that x position to put inside of this value area.
06:16And then let's say I would add another 240.
06:19So that would make sure that whatever my x would be,
06:22it would automatically be 240 pixels more in the beginning.
06:27So that way, when I animate it, it's
06:29going to come from 250 pixels before and roll itself in.
06:33That's beautiful.
06:35But a nice little shortcut to do the exact same thing
06:39is instead of typing a number here, all we have to do
06:42is send a string.
06:43So if you send, and I'm just going to, you know,
06:45just copy this so in case someone wants to look at it
06:49and compare between the two, I'm just going to comment it out.
06:53And I'm just going to show the same thing.
06:55But this time around, I'm going to send this value in
06:57with just 240 wrapped up inside of a string.
07:02If I wrap it inside of a string, the engine
07:04is that smart, which is probably,
07:05it is my favorite feature.
07:07It saves a lot of, well, it saves a little bit of code,
07:09which is always a good thing.
07:11And if you run it again, you're
07:12going to see that it's going to automatically understand
07:14that what you meant was 240 pixels to the right.
07:18Now, the same thing goes for any value.
07:22But if you want it to be negative and not positive,
07:24and you want to move it from whatever it was,
07:26but go a little bit negative.
07:29So let's say, for example, for our team names,
07:31we want it to move, you know, like, let's say, minus 30
07:36from, let's say, we want it to move minus 30 degrees.
07:41I'm not saying degrees.
07:42I don't know why I'm saying degrees.
07:43But if our x, and let me just go there for a second.
07:45If our text is right here, right now it's
07:47animating all the way to the top.
07:48You're both the x and the y.
07:50But what if I wanted just to move it to the left 30 pixels
07:53to basically subtract my x by 30 pixels?
07:57To do that, all I have to do is just send a minus
07:59inside of that string.
08:01So I'm just going to send it a string value.
08:02And then just inside of it, just type minus 30
08:04or minus whatever amount.
08:06So literally, by putting a string and then setting
08:08a value of minus, we're pushing it to the left.
08:12In our case, it's to the left.
08:13So if we're animating something like a visibility
08:15or something of that nature, then obviously
08:17it doesn't need to do it left or right.
08:18But we're subtracting from the value or adding to the value.
08:21So it could be or minus or plus.
08:22Or if you don't put anything, then it's just as if you put a plus.
08:26So that is that.
08:28So you can see that our text is now, oh, I was actually
08:32going to move the x, but I didn't move the y.
08:35So let me just knock alpha down or let's alpha to 0.5
08:39so we could all see it more easily.
08:42So it moved, but it didn't really move that much.
08:45So let's do this a little bit more.
08:47So it's going to be a lot more visible.
08:49So let's say 130.
08:50So that way, we'll see that move.
08:53OK, so we're seeing that move.
08:55So there you go.
08:55Now, the last thing I want to talk about this.
08:57And before we move on to chapter 2,
09:00where chapter 2 is going to be,
09:02we're going to go into the tween light.
09:04Everything we've done so far is completely
09:06relevant to tween light and to tween match.
09:09It works in the exact same way.
09:11The only difference, as we said, is the tween nano
09:13is just not part of the big library.
09:19So you can't actually add plug-ins.
09:21So if you wanted to do a tint, you just
09:22can't do it if you're using tween nano.
09:24So really, in general, if you don't
09:26have a really crazy constraint of size,
09:28if it's not planned for a really small banner
09:31and it's actually going to be for a website or application,
09:34just always start from tween light.
09:37So I'm going to go back for questions really quickly,
09:40and then we'll continue.
09:42So I'm going to just go back there.
09:43Are there any questions?
09:48Yeah, tween nano does use easing.
09:50You could use easing with tween nano.
09:52And really, in general, the tween nano
09:56does almost everything.
09:58It just doesn't do it as clean as all the rest.
10:03But it does do eases.
10:11I don't remember.
10:13I believe so.
10:14I believe it does.
10:15Yeah, yeah, it does do on complete.
10:17It does.
10:17But there's some properties that it doesn't do.
10:20So for example, if I give me a second here,
10:23let me look at my notes.
10:26So with the tween nano, for example,
10:28and some of you don't know what the guys are talking about,
10:33is basically, what if you want to do another something
10:36when the animation is complete, which
10:37we're going to see that really soon when
10:39we move into the tween light world.
10:43Let me just scroll here quickly to give you
10:45a more accurate answer.
10:49Let me see.
10:56There you go.
10:57See, it does accept on complete.
10:59And it gets and accepts on update.
11:01So those are the two dispatches that create.
11:03On complete and on update, those are the only two.
11:07And when you go into the tween, there's no on start.
11:09And on start only exists from tween light enough.
11:12So tween nano is more minimalistic.
11:14What we're talking about, it gives you
11:16the core features that you need.
11:17Now, for anyone that doesn't know what we're talking about,
11:19we're going to look at this in a couple of minutes.
11:21But just really quickly, on complete,
11:22just lets you know when the animation is done,
11:24so you could do the next thing that you want to do.
11:26On update, on the other hand, enables
11:28you to get updates every single time the animation is
11:31happening.
11:32So every time something moves or changes in animation,
11:35something starts.
11:36So I want to talk about one more thing about tween nano
11:39before we move on to the tween light, which is really
11:41one of the biggest differences.
11:44Because in general, almost all the stuff
11:47we're going to be talking about in the next hour
11:49exists also in tween nano, by the way.
11:51And if it doesn't, then I'll try to tell you
11:55that it doesn't exist in tween nano.
11:56But there's only one thing that is really different
11:59in tween nano.
11:59I want you guys to be aware of it.
12:02It's kind of confusing.
12:04So we'll show just a little bit of it.
12:06I'm not going to dig too deep into it,
12:08because I want to go to the more fun stuff that
12:10are more connected to animations.
12:12So I'm going to start doing that.
12:14If there's any further questions on that,
12:16I'll be back to that in a few seconds.
12:18So back into our example chapter, I
12:21want to talk about one more thing.
12:24And I'm going to show you this new property.
12:28I'm going to add another animation.
12:30And let's just start with adding this animation, tween nano.
12:33And I'm going to do a two.
12:35And I want to take that T names again.
12:37And I want the animation to be a really short animation,
12:400.3 seconds.
12:43And this time around, I want to set my alpha to be 1.
12:48Now, I'm going to set my alpha to be 0 here.
12:53And I want to add one more property
12:54that we haven't talked about yet,
12:56which is the capability of delaying animations.
12:59So I'm going to delay my animation by 0.5 seconds.
13:03So the delay itself is the extra property.
13:06It doesn't belong to the actual object.
13:08It's the first property out of many
13:10that enable you to add configurations for your animations
13:13through that extra object that we're sending inside.
13:16If it's a property of the object, it would animate that object.
13:19And if not, it's a reserved property
13:21of tween light or tween nano, tween max,
13:24in our case, tween nano.
13:25So the delay basically gives me a half a second delay.
13:29Nothing will happen with this for half a second.
13:31And then after that, it will start.
13:33Now, we're going to have your conflict,
13:34a conflict of interest.
13:35Because if we're going to look at our line one,
13:37line one is an animation that fades our element to 0.
13:42And it takes it a second.
13:44But on our last line here, we're adding a new animation
13:46that completes in 0.8 seconds.
13:50So what will happen?
13:51Will this win or will this win?
13:55Now, in tween nano, contrary to tween light and tween max,
14:00which are a little bit smarter, if you create an animation
14:03right after the first animation,
14:06it doesn't really matter.
14:08This will win.
14:09So if I run my animation now, and even
14:11though we're expecting our copy to stay,
14:13notice what happens is it's going to fade in and then
14:15disappeared.
14:16Because for the first 0.8 seconds,
14:18there's a competition between fading out and fading in.
14:22But once this is over, this completes and finishes.
14:27So this is the biggest, biggest difference between tween
14:30nano and tween light.
14:32There's a few things that tween nano doesn't have at all.
14:36And you'll discover them as we're working.
14:39And as we're going through this hour,
14:40and I'm sure as you start working more deeply
14:42into tween max and light and so on and so forth,
14:46but that's the biggest difference.
14:48Now, I want to show you how could you
14:49change the basic property.
14:53Now, by default, tween nano doesn't override anything.
14:57It doesn't override animations.
14:59In other words, whatever you're animating is animating.
15:01You can animate 20 times the same thing.
15:03They'll just be fighting over each other,
15:05add their animating it, and just complete an amount of seconds
15:08that they're supposed to.
15:09You could send another property, which is called over right.
15:13And by setting the property over right,
15:15you could have basically, if you don't put nothing,
15:17that's the default where there's no over right.
15:20But you could send the property of all.
15:22That's the only option you have in tween nano.
15:25Now, when you set the property of all,
15:26it will automatically override.
15:28But it's going to create an animation
15:30that we don't read anymore.
15:31And let's see what I mean.
15:32If I run this animation, you'll see that one thing,
15:35you'll see what it does.
15:36Does anyone notice, by the way, and I'm
15:38just going to show you this animation one more time.
15:41And I'm going to stop it.
15:42I'm going to go to the question and answer
15:43to see if anyone here recognizes what does all actually do.
15:48What is the difference between having all, not having all?
15:50We're watching it with the all right now one more time.
15:53I'll show it to you without it.
15:54And you tell me, what does the override all actually
15:57do physically?
15:59OK.
16:00So this is the animation as it was before we put the all
16:03there.
16:04And as soon as we put the all there,
16:06this is how it looks like.
16:08So it stages you guys, yours, and I'll
16:10explain what it actually is doing
16:12if you guys didn't hit the nail.
16:18Well, you couldn't say it any better, Pavel.
16:20But the biggest thing here is that it overrides everything
16:23and it actually stops it from ever happening.
16:26So even though it's not even happening at the same time,
16:29so the last animation, exactly, it just basically kills.
16:33And any animation that was there before, exactly.
16:36So literally, this never happened.
16:38You could have wrote, you've cut a written here 500 animations,
16:42but this is the only one that will execute
16:43because we put your all.
16:45Now, technically speaking, I don't
16:47think this is useful, really.
16:48So this is where Twin Nano kind of loses its charm.
16:52If you're creating intricate animations,
16:54Twin Nano just isn't really that great for it.
16:57And you have to move up to the Twin Nano.
16:59Well, in Twin Nano, it works much better
17:01because by default, Twin Light only overrides
17:07whatever was changed.
17:08So if I didn't put any override at all
17:10and we're working in Twin Light, let me just show that to you.
17:13So I'm just going to import Twin Light.
17:21And I'm just going to quickly just swap my Twin Nano
17:24with Twin Light.
17:25Just we're going to animate with Twin Light.
17:27It's the exact same animation as we were doing before.
17:29And notice the really massive difference between the two.
17:32By default, not only did the animation not override it,
17:36only changed what it had to change.
17:38It's literally doing exactly what we would hope for it to do.
17:41And the reason why I'm saying it's exactly what we hope for it
17:43to do is because the only property we changed
17:45was the alpha.
17:47In other words, we would expect the x and y
17:50to continue animating for one second, for the alpha
17:53to animate for that one second,
17:55until that half a second kicks in.
17:57And then this animation should take 0.36 seconds to fade in.
18:01Now, I don't know how the internet connection is,
18:03but you'll see exactly it's doing what
18:05we would hope for it to do.
18:06It's fading out, gets halfway through.
18:08It starts fading in.
18:10It completely fades in, and it continues moving to its spot.
18:13And that's exactly why you really usually
18:15would want to work with Twin Light,
18:17because Twin Light is a lot more intuitive,
18:19and it enables you much more easily to layer in animation.
18:24And because of that, it makes it a lot more interactive.
18:27So for example, if I had there some sort of mouse tracking,
18:30or I had there some sort of feature that was interacting
18:33with the user itself, if I was using the Twin
18:35Nono, I would probably create really choppy animations,
18:39because they're not intended to ever stop.
18:41So when you're using Twin Nono, you're
18:43expecting the animation to start and complete
18:45without ever intervening in it, or if you are very, very
18:49slightly and very, very controlled.
18:52While the Twin Light is built in by default
18:55to know how to deal with changes, because it's built for that.
18:58So the animation has more code.
19:00It's more responsive, and it creates animations
19:03that are a lot more engaging because of that,
19:05because you could, on the fly,
19:07change things as much as you want,
19:09and no one's going to complain.
19:10Twin Light will do it really, really brilliantly.
19:14So that covers our chapter one.
19:17That covers our conversation about Twin Nono.
19:19Now, a lot of the stuff that we're
19:21going to be talking about in our next chapter
19:23that we're going to get into in a second
19:26is completely relevant to Twin Nono as well.
19:28The only thing that is not is that,
19:30and I'm just going to undo what I just did here,
19:33the only thing that is not relevant is that override.
19:35And that override is the biggest, biggest difference,
19:38for me at least, between Twin Nono and Twin Light,
19:41making Twin Nono almost not really usable.
19:44So the only time I would use this is if really I have a client
19:47and they tell me this has to be 10 kilobytes and not
19:50more than that, then obviously I
19:51wouldn't be able to use Twin Light because it would take away
19:54six or seven kilobytes out of my project.
19:56So I would probably have to go to the Twin Nono
19:58and then I would obviously create an animation that
20:01is not interactive because I would avoid touching
20:04my animations as they're animating,
20:05because it would be much harder to manage them.
20:07All right, so I'm going to go back for quick questions
20:10to see if there are any questions.

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!