Game Development Reference
Figure 9-1. The physics project
You'll notice that the project contains five classes: Lh]uan[=__ahan]pekj, Lh]uan[Bne_pekj, Lh]uan[
>kqj_a, Lh]uan[Cn]repu, and Lh]uan[Fqil. The Library contains a symbol called ?]p, which is the
player character. You'll see the use of physics in motion by binding the cat symbol to these different
Let's start with the simplest of these types of motion: acceleration.
Acceleration means to gradually increase velocity, just as your car does when you give it some gas. To
gradually speed up game objects, you need to add a value to your object's rt or ru properties in an
AJPAN[BN=IA event. You might recall from Chapter 6 that rt refers to “velocity on the x axis” and ru
refers to “velocity on the y axis.” In a nutshell, these properties represent an object's speed, traveling
either horizontally or vertically.
In AS3.0, if you gradually want to increase an object's velocity on the x axis, you need to use an addi-
tion assignment operator ('9) to add the value of the acceleration to the rt property. Your code might
look something like this:
On the y axis, your code might look like this:
Where did ,*. come from? That's the value of acceleration. Exactly what the number is depends
entirely on you and how quickly or slowly you want the object to speed up. A larger number such as
,*2 makes the object accelerate faster, and a lower number such as ,*- makes it accelerate much
more slowly. Choosing the right number is just a matter of trial and error and observing the effect it
has on the object.