02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous Video
Chapter is concluded.Next is

Playing with the PhysicsPropsPlugin

In this chapter, we will explore the PhysicsPropsPlugin that enables us to create isolated physics related animations per property. In this lecture, we will play with the PhysicsPropsPlugin and see it in action.

Video Transcript

00:00In the last lesson, we've set the stage
00:03for our props physics props plugin.
00:06So let's go ahead and start working on it.
00:08And even before we do that,
00:09I wanna make sure that I have a reference
00:11to all these divs I've just created.
00:13Div is probably not the right word anymore,
00:15so I'm gonna call it or adivs or just divs.
00:19So I'm just gonna call it divs,
00:21because for me that is logical.
00:24And I'm gonna go ahead there
00:25and just get a reference to those divs.
00:27And in our case,
00:28because I replaced everything inside of our body,
00:32excuse me, all I have to do is just ask for all the divs
00:35and I'll have all the divs.
00:37All right, next step process,
00:38I'm gonna go ahead here
00:39and I'm not going to create a div again
00:41or append again because I don't need to.
00:44And next item for me is,
00:45and I'm not gonna create any randomness
00:47in our animations either.
00:48You guys could play around with those properties.
00:51I wanna jump right in there
00:52and show you how to work with the tween plugin itself.
00:55So I'm gonna go ahead there and create a tween max.
00:57I'm gonna animate it too.
00:58And I'm gonna get a reference to that divs,
01:01to the item currently in focus
01:03and go ahead and define how long I want my animation to be.
01:07And I'm gonna go right to my physics plugin,
01:10my physics props plugin.
01:14And I'm gonna go ahead and just create here a new object
01:18and define what do I wanna animate
01:20by starting with the X position.
01:22And I could define any variable separately
01:24and define for it the velocity,
01:27the acceleration and the friction.
01:28But let's just start quickly with the velocity.
01:32And that was not velocity, let's try it again.
01:36And I'll set a velocity of 100.
01:38Now let's just run it to see what would happen.
01:40We should see all the items moving 100 pixels a second
01:43for two seconds.
01:44So I go ahead and I click on refresh
01:47and I click on refresh
01:49and I click on refresh, nothing is happening.
01:51And let's see what's going on.
01:53So am I getting the divs?
01:54I'm getting the divs.
01:56Did I write here physics?
01:57No, I didn't, I'm missing a Y.
01:59Let's go ahead and try this one more time.
02:04And we got another typo.
02:06So let's figure it out.
02:07Okay, so physics, physics pros, which is not it either.
02:11I'm getting too much in a hurry.
02:13Physics props velocity, that is true.
02:17All right, so let's give it one more try.
02:19And here we go, our items are animating
02:21at 100 pixels per second in the same direction
02:25and in the same velocity.
02:26Let's go out and continue with the other two properties
02:28that we said we could control.
02:30I'm gonna go ahead and add here also acceleration.
02:36And I'm gonna set an acceleration of let's say 50
02:40and I'm also gonna set here a friction
02:42and I'm gonna go ahead and set here a friction
02:46and I'll set that friction to be 0.05
02:49or 0.06 for that matter.
02:51Go ahead and click on refresh
02:53and now we should have that animation changing
02:57as it's going through.
02:58Now beyond that, we don't have to only affect the X.
03:01We could also, if we wanted to affect the Y coordinate
03:06as well or any other property really
03:08because it's giving us that separation of control.
03:10And if I wanted to, I could set the exact same thing
03:13to both of them or not, use the physics props
03:16and have a lot more control over each property separately
03:19having going in completely different directions
03:21according to whatever plan I have for them.
03:25So I go ahead here and click on refresh.
03:27We'll see that now they're all going again
03:29in a very linear motion
03:31but that's because our values here are very similar.
03:33If I go ahead here and I change the velocity
03:35to be let's say 300
03:37and I'll set the acceleration to be minus 50
03:39and I'll set here a friction of 0.2.
03:42Now obviously 0.1 and by the way,
03:44or no friction at all.
03:45How about we don't put any friction to Y at all
03:47but we only put a friction onto the X coordinate.
03:50Literally play with it.
03:51You have a lot of capabilities,
03:53a lot of control that you could define to your animation
03:56and the way you would want it to work.
03:59Now obviously to create a real animation
04:01that has a lot of effect and modularity
04:04we'd probably wanna add all these stuff
04:06to be completely dynamic
04:07or some sense of dynamic nature to it
04:09which we're not doing at all just for the sake of time.
04:13So that's it for this chapter.
04:15It's a much more simple chapter
04:17but I encourage you to come up with your own interpretation
04:20and really getting familiar with the differences
04:22that you saw between the physics props
04:24and the physics 2D plugin
04:29which the physics 2D plugin is probably the easiest
04:31and most straightforward
04:32because you don't have to worry about all the details
04:35and the physics plugin breaks it down
04:37and gives you access to each property separately.
04:40Sometimes you'll need it, sometimes you won't need it
04:42so it really just depends on the situation.
04:44So being familiar and knowing how to work with both
04:46is gonna be a very useful capability.
04:50So I look forward to seeing your interpretation
04:52and your animation and what you create with this plugin.
04:55We'd love to see it in the comment section below.

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!