Game Development Reference
In-Depth Information
// Set up Box2D World
setupPhysics();
}
public function dispose():void
{
mPhysicsEngine = null;
mConfig = null;
mPlayer1 = null;
mPlayer2 = null;
mPuck = null;
mGoal1 = null;
mGoal2 = null;
mPlayer1Joint = null;
mPlayer2Joint = null;
mCollisionBodies = null;
}
Intheconstructor,wesimplypassandstorethe AirHockey-
EngineConfig object and then call setupPhysics , which we
ll examine
next. The dispose function, which the Game class calls, simply nulls
out every member variable.
'
private function setupPhysics():void
{
mPhysicsEngine = new b2World(new b2Vec2(), false);
// Create paddle bodies
mPlayer1 = displayObjectToCircle( mConfig.mPlayer1,
mPhysicsEngine );
mPlayer1Origin = mPlayer1.GetPosition().Copy();
mPlayer2 = displayObjectToCircle( mConfig.mPlayer2,
mPhysicsEngine );
mPlayer2Origin = mPlayer2.GetPosition().Copy();
// Create paddle reaction joints
var jointDef:b2MouseJointDef = new b2MouseJointDef();
jointDef.bodyA = mPhysicsEngine.GetGroundBody();
jointDef.bodyB = mPlayer1;
jointDef.target = mPlayer1.GetPosition();
jointDef.maxForce = 300.0 * mPlayer1.GetMass();
mPlayer1Joint = mPhysicsEngine.CreateJoint( jointDef ) as
b2MouseJoint;
jointDef.bodyB = mPlayer2;
jointDef.target = mPlayer2.GetPosition();
jointDef.maxForce = 300.0 * mPlayer2.GetMass();
mPlayer2Joint = mPhysicsEngine.CreateJoint( jointDef ) as
b2MouseJoint;
// Create puck and goals
Search Nedrilad ::




Custom Search