Game Development Reference
In-Depth Information
might need in order to handle the collision. Listing 13-20 shows the implementation of
the notifyAB method.
Listing 13-20 . Implementation of the Box2D Contact Methods
void ContactListener::notifyAB(b2Contact* contact,
NSString* contactType,
b2Fixture* fixture,
NSObject* obj,
b2Fixture* otherFixture,
NSObject* otherObj)
{
NSString* format = @"%@ContactWith%@:";
NSString* otherClassName = NSStringFromClass([otherObj class]);
NSString* selectorString = [NSString stringWithFormat:format, contactType,←
otherClassName];
SEL contactSelector = NSSelectorFromString(selectorString);
if ([obj respondsToSelector:contactSelector])
{
Contact* contactInfo = [[Contact alloc] initWithObject:otherObj
otherFixture:otherFixture
ownFixture:fixture
b2Contact:contact];
[obj performSelector:contactSelector withObject:contactInfo];
contactInfo = nil;
}
}
The format string defines the general naming format of the selectors that will be called.
The syntax of the selectors that notifyAB calls is as follows:
<contactType > ContactWith < otherClassName>:(Contact*)contactInfo
The contactType is the string you pass to the notifyObjects method, which
will be either “begin” or “end” in the current implementation. The other-
ClassName string is obtained from the NSStringFromClass method, which
takes the class of the otherObj . For the collision events of the ball and the plunger,
 
 
Search Nedrilad ::




Custom Search