Game Development Reference
In-Depth Information
Collision Callback Methods
Now it's time to fire up Xcode once more to add code that runs a so-called
callback meth-
od
whenever specific collision events occur.
Implementing the Collision Delegate Protocol
Before you can receive contact callback messages, there's a little setup necessary in order
to register the
GameScene
class with the CCPhysicsBody of the level, as referenced by
the
_physicsNode
ivar.
Listing 4-9
.
The GameScene interface
#import "CCNode.h"
@interface GameScene : CCNode
@end
In order to allow the class to be used as a receiver of physics collision messages, it must
implement the
CCPhysicsCollisionDelegate
protocol. This is done by simply
Listing 4-10
.
GameScene is now said to adhere to the CCPhysicsCollisionDelegate pro-
tocol
#import "CCNode.h"
@interface GameScene : CCNode <CCPhysicsCollisionDelegate>
@end
In
GameScene.m
, you can now register
self
as the collision delegate of the
_phys-
Listing 4-11
.
Assign the GameScene instance as the _physicsNode's collision delegate
-(void) loadLevelNamed:(NSString*)levelCCB
{
Search WWH ::
Custom Search