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

Frames, seconds and FPS

Traditional animation was drawn frame by frame. On a computer each rendering acts as a frame. JavaScript natively doesn't have a timeline or a visual editor but it does have frames and time. Frames and time are the core building blocks for a timeline. Before we start working with timelines it's important we understand the relationship between time and frames. In this lesson, we will understand the relationship between time frames - FPS.

Video Transcript

00:00Before we jump into the world of timelines, I wanted you to know that every single tween in the
00:06tween in the GSAP library actually exists inside of a timeline. It's one that is kind of invisible
00:13to you and one that you don't have any control over. In this lesson we're going to take a first
00:18step into understanding what timelines are, how do they look like, so we can then take advantage
00:23of them throughout the next chapter which is going to be dedicated to timelines. But we're
00:28going to start off talking with the concept of frames and what they are and the difference
00:32between frames and seconds before we move on into the actual timeline. It started with chapter two
00:36and the first thing we're going to stay in the same sample that we were in in chapter one,
00:41but now we're going to move into understanding what are timelines and how do they work.
00:46And actually even tween light that we've been working with has a primitive timeline associated
00:51with it. Now you might ask yourself what is a timeline and to illustrate it what I'm going to
00:58do is I'm going to go into Adobe Flash and don't worry you don't need to have Adobe Flash but you'll
01:03find our sample there as well in our source files inside of the Flash folder. Now I created a small
01:09little image here that basically is animating from frame one to frame 30 and in animation
01:16in general there are basically two mechanisms and if you've worked in any animation tool
01:21there are basically two mechanisms how to count and adjust your animations. One is how many frames
01:26your animation will have. In this case this animation has 30 frames and the other is how
01:32long will these animations take place and if you take a peek here on the bottom here you're
01:36going to see that there are 24 frames per second right now. So if I go ahead and animate
01:42this animation and just for a second here you know let me run it one more time you're going
01:47to see that our animation let me run it one more time and let me try it again all right that was
01:57close enough for some reason I can't get it into the screen as it's animating oh all right there
02:01you go so basically that took us one second or actually a little bit more than a second because
02:06but what if we wanted it to be exactly a second we could have a choice of or setting it to 24
02:11frames which is our FPS or setting our FPS to be 30 frames a second now once you start adjusting
02:18frames per second it doesn't really mean that it's actually going to make it in that amount of time
02:23it's more of a suggestion because if your local computer that is running this doesn't have the
02:28horsepower to be able to run your animation in that duration of time then it could take a longer time
02:35on the other hand if we have your art our 30 frames and we want to change it to 15 frames
02:40a second then 50 frames will take this animation which is the same but because our
02:44animation timeline is not talking about specific timing it gives us much easier control over the
02:50speed of our animation based on whatever we want it to be so that's really the biggest
02:56reason and the biggest rationale behind it is because traditional animation happens on frames
03:02we're going to go back and forth into this example as we continue actually coding so
03:06because it really illustrates the idea really really well when you could visualize those frames
03:11because it makes it really simple so now that we know what frames are let's see what does that
03:16actually mean for us in our case throughout our training when we were creating our animations we
03:22told you that the first item here is the actual amount of seconds but really that wasn't 100%
03:28true because it could be or seconds or frames if i wanted this any time reference to our element
03:36to be a reference that is based on frames instead of on seconds all i have to do is go into the body
03:42of the object itself that i'm sending through and make sure that i'm setting a property called
03:47use frames and set it to be true once i've done that and let me just uh make sure that i'm uh
03:53board wrapping again and once i've done that once i've done that then now this is three frames
04:00the animation will be of three of three frames so that uh zoom in animation will have a delay
04:07of one and a half frames which is not really possible so we'll have to make a delay of two
04:11frames and if i have here a delay of two frames and i run it i'll see that my animation is going
04:15to take place really fast the zoom in itself so you see the zoom in was done even before
04:21i've even noticed anything it was so quick one two three it's already zoomed in even before
04:26the fade-in was complete now that obviously is not a realistic amount so if i set here more
04:33something more accurate which probably maybe let's say 45 frames and i'll have your a delay of let's
04:38say 45 frames as well now the animation obviously is going to take more time and i'll be able to see
04:44that zoom in effect which i've couldn't see earlier because my frame rate was really fast
04:49and it automatically just did it really quickly before i've even noticed it now if you're asking
04:54yourself what is your frame rate or how could you control your frame rate that's easy as well
05:00what you do is you approach and best to do that before you do anything else really so i would do
05:04that literally as one of the first things you do in your application unless you're trying to create
05:08some sort of dynamic frame rate which is definitely a possibility you would go into your
05:13time light ticker and then type fps for frames per second and define how many frames you want
05:21per second now by the way this relates to all tween light instances so if i set my fps to be 30
05:27frames per second that's going to be my frame rate for all my animations if i go ahead here
05:33and click on refresh again we're going to see that we have a delay of one and a half seconds
05:37and the zoom in is one and a half seconds as well because i had 45 and 45 and same applies
05:44i can make it even larger or smaller so i could say hey i want my frame rate to be 15 frames a
05:48second which means we're going to refresh our view 15 times a second and that means that this will be
05:54three seconds and this will be three seconds so we should have here a delay of three seconds
05:59and three seconds of animation now notice how all these other animations are being adjusted as well
06:05because if this is a one second animation it's only going to have 15 frames in it and if this
06:10is a a four second animation you would have here 30 60 frames so you'd have your 60 frames
06:17and our delay here would be of one half seconds but it would be basically about 27 frames delay
06:25so if i save this and run this one more time we're going to see that now we're going to get that
06:29three second zoom in effect that's going to be very slow and very non-natural now yeah
06:38obviously this is not really a scenario where you would want to create frames instead of seconds
06:42in general probably frames are easier to work with unless you have a really big amount of items
06:47that you want to animate and you don't want to be confused by how many seconds they're going to
06:52animate because for example you might be animating it over and over maybe you have some sort of an
06:57effect of something that's animating and every round animates a bit faster and a bit faster and
07:02a bit faster you could literally use the same mechanism to just run through over and over and
07:08all you have to do is upgrade your frame rate that and by upgrading your frame rate you're going
07:13to speed things up and still get the same visuals still get the same details of of animations so
07:20maybe have some sort of a slow-mo effect and after that you want to run it again but quickly and
07:25efficiently a very very theoretical scenario obviously all right so that's it for this and
07:31in the next lesson we're going to continue delving a little bit deeper into frame frames don't
07:35really worry about where you could use these frames right now because you're going to get it
07:39throughout the chapter you're going to see where does it position as we go into timelines and see
07:44how to work with timelines which is is going to be our immediate next topic of creating our
07:49own timeline now that we know what a timeline is that we know that it works based off of seconds
07:54and also frames there's always an amount of frames that are rendered a second which you could
07:59let it happen dynamically or you could control it yourself and decide how many frames will be a
08:04second obviously if you put a high value there that has unrealistic such as a thousand it's
08:10never really going to do a thousand frames per second it's just going to try to do as much as
08:14it can per second so it's not going to cross the the threshold of capability of that computer
08:20but it's really about controlling it when you want it to be less than that capability
08:24when you want less frames refreshing a second all right so that's it for that and we'll see you
08:29in the next lesson when we start creating our own timeline and seeing how timelines actually work

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!