Game Development Reference
In-Depth Information
Given all this talk about the differences between how GameController and a Box2D world progress
the actors in their scenes, you may think that getting these two classes to work together is going to
be tricky. It is not. We are simply going to ignore this issue in this example and not take advantage of
this feature of Box2D. I wanted to point out this difference in case any readers are looking to make a
complex physics game, in which case they will want to account for this early in their design.
The Bodies
Once a world is created, we want to put something in it—those things are called bodies. A body
represents the location, angle, velocity, and other physical attributes of an object in the world. Here
is the full list of attributes:
Type - Either static, kinematic, or dynamic
Position - A point in world coordinates
Angle - The rotate of the body
Linear Velocity - A vector describing the current velocity of a body
Angular Velocity - A vector describing the rotational velocity of a body
Linear Damping - How much the linear velocity is reduced over time
Angular Damping - How much the angular velocity is reduced over time
Allow Sleep - A flag indicating that the world can use an optimization that
ignores this body when appropriate
Awake - A flag indicating that the body is currently being used in the simulation
(not asleep)
Fixed Rotation - A flag that prevents the body from rotating
Bullet - A flag indicating the simulation should pay special attention to this
fast-moving body to prevent “tunneling”
Active - A flag indicating that the body is participating in the simulation. If a
body is not active, then it does not participate in the simulation until active is set
to true by user code
User Data - A place to attach additional data to a body
Gravity Scale - The effect that gravity has on the object
There are a few items in the above list that require a little more explanation. The type of a body
dictates how it interacts with other bodies in the world. A static body will never move or rotate,
but another body may hit or bounce off it. A kinematic body is similar to a static body but moves
according to a velocity, like a moving platform in a game. A kinematic body will not collide with
other static or kinematic bodies. A dynamic body moves according to the laws of physics; it collides
with all other types of bodies. In a game, a dynamic body may be a block, ball, bird, pig, or what
have you.
 
Search WWH ::




Custom Search