Acceleration, Friction, and Wrapping

Employing Acceleration

We still aren't "accelerating" that object so much as setting the velocity. What's the difference between velocity and acceleration?

Velocity is a measure of speed at one instant in time. Acceleration is the change in speed between two instances.

Let's get hands-on. We'll start by changing our conditional statements:

Key presses will now change the variable ySpeed... which means nothing will happen with the ship! Let's add ySpeed to ship._y contstantly. This command goes outside the conditional statements, but remains part of the onEnterFrame function:

Finally, let's initiate ySpeed at 0, so the ship doesn't run right off the screen as soon as the program starts. This is what the updated Actions window will look like:

ySpeed Actions

Test it , but be careful! The ship will quickly run right off the stage:

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player