Game Development Reference
In-Depth Information
-(void) initPhysics
{
b2Vec2 gravity;
gravity.Set(0.0f, -10.0f);
world = new b2World(gravity);
world-> SetAllowSleeping(true);
world-> SetContinuousPhysics(false);
contactListener = new ContactListener();
world-> SetContactListener(contactListener);
...
What remains is to delete the contactListener in the dealloc method to free
its memory, because it's a C++ class object:
-(void) dealloc
{
delete world;
world = NULL;
delete debugDraw;
debugDraw = NULL;
delete contactListener;
contactListener = NULL;
}
Now the boxes in the PhysicsBox2D01 project will be tinted purple whenever they
touch other boxes. The implementation isn't perfect, as you'll notice. Some boxes
clearly collide but may not be colored. The problem is that EndContact may be
called for a body which still has other contacts. But for demonstration purposes it suf-
fices.
Joint Venture
With joints, you can connect bodies together. The type of joint determines which way
the connected bodies are connected. In this example method, you create four bodies
total. Three are dynamic bodies connected to each other using a revolute joint , which
keeps the bodies at the same distance but allows them to rotate 360 degrees around
each other. If you find it hard to imagine how these objects might behave, you should
Search Nedrilad ::




Custom Search