Game Development Reference
mPuck = displayObjectToCircle( mConfig.mPuck,
mPuck.SetLinearDamping( .8 );
mPuckOrigin = mPuck.GetPosition().Copy();
mGoal1 = displayObjectToBox( mConfig.mPlayer1Goal,
mGoal2 = displayObjectToBox( mConfig.mPlayer2Goal,
for each (var boundary:DisplayObject in mConfig.
displayObjectToBox( boundary, mPhysicsEngine );
mCollisionBodies = new Vector.
When setting up a b2World object, you can define certain prop-
erties of it, such as gravity and whether objects are allowed to
sleep (that is, be removed from the calculations of the simulation if
re not moving). In our case, since the gravity of our game is
downward through the z -axis of the board, we don
sics engine to apply gravity. Passing an empty b2Vec2 gives us a
gravity of 0. The next few lines create the body objects for the pad-
dles and copy their original position for the origin objects. You
notice that this process uses a method called displayObjectToCircle .
This is a static function we
ll look at shortly. It takes a display
object and the corresponding b2World object and performs all the
the visual representation into a mathe-
matical circle. For the walls, we
ll use a very similar function, dis-
playObjectToBox , which works for rectangular objects.
After defining the bodies for the paddles, we need joints to attach
creating a new joint definition of the type b2MouseJointDef. Joints
have to have two bodies to work, so the first body we supply is the
and the second is the paddle to which it will attach.
The target of a joint is the position to which it wants to move. When
reading input later on, we
ll change this target vector to reflect the
position of the player
s finger. This change in target will cause the
joint to react, exerting a force on the paddle body. The last thing we
property, which, according to the Box2D manual, is
used to prevent
violent reactions when multiple dynamic bodies interact.
of it as a throttle on the force you can exert. I wish I could say
lated carefully. Unfortunately, like so much of working with physics