It's relatively easy to handle collisions within Cocos2d when using Chipmunk (as is pretty much everything else in Cocos2d). That is why so many developers use Cocos2d. To do so, we need to do a few different steps so that Cocos2d can properly detect and handle our collisions.
The delegate pattern is a common way to handle messages sent by a class to any of its potential parent classes. For example, if you want to use UITableView
(which is the standard table in UIKit
), you must set the delegate of the table view to the class you're adding it to so that when the table view tries to refresh the data in the table, it knows which class' methods to call.
That being said, we need to tell MainScene
that it will be a delegate for our collision handler, so open up MainScene.h
and add CCPhysicsCollisionDelegate
to the @interface
line. This will allow the CCPhysicsNode
object to set collision detection events on our MainScene
class:
@interface...