Game Development Reference
In-Depth Information
}
void ContactListener::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
{
// do nothing
}
What does the notifyObjects method do? Extracting the two colliding bodies and
obtaining their user data pointer is similar to Listing 13-17 . But take note of the differ-
ences:
void ContactListener::notifyObjects(b2Contact* contact, NSString* contactType)
{
b2Fixture* fixtureA = contact- > GetFixtureA();
b2Fixture* fixtureB = contact- > GetFixtureB();
b2Body* bodyA = fixtureA- > GetBody();
b2Body* bodyB = fixtureB- > GetBody();
NSObject* objA = (NSObject*)bodyA- > GetUserData();
NSObject* objB = (NSObject*)bodyB- > GetUserData();
if ((objA ! = nil) && (objB ! = nil))
{
notifyAB(contact, contactType, fixtureA, objA, fixtureB, objB);
notifyAB(contact, contactType, fixtureB, objB, fixtureA, objA);
}
}
In this case, you simply assume the user data pointer to be a pointer to an Objective-C
class derived from NSObject . This provides the flexibility that any object can re-
spond to collision events, not just BodySprite objects. If both user data pointers are
not nil , then the notifyAB method is called twice, the second time with the A and
B variables switched. This ensures that both objA and objB receive the collision noti-
fication, and the notifyAB method only needs to handle one case.
The job of the notifyAB method is to construct the selector that should be called and,
if possible, call the selector with any contact information that the receiving object
Search Nedrilad ::




Custom Search