Search code examples
cocos2d-iphonespritebuilder

CCPhysicsCollisionDelegate not called


I'm stuck for 2 days now on collision detection. I tried every solution suggested in the forums, and the collision delegate methods are still not being called called. I'm using cocos2d v3.4 bundled with SpriteBuilder v1.4.7.

Here is my simple test: smallBox and bigBox are both children of _physicsNode

1- Enable dynamic physics on the small box, and set the collision type to "smallBox"

2 - Enable static physics on the big box and set the collision type to "bigBox" enter image description here

3 - Publish, build and run in Xcode, outputting the collision types of each node so i can make sure they're properly connected, and correctly setting the collision delegate of _physicsNode.

Result: collision delegate methods are not called when small box falls on big box.enter image description here


Solution

  • Should replace the "typeA", "typeB" of the delegate method to the actual types "smallBox" and "bigBox", so a valid callback would be this:

    -(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair smallBox:(CCNode *)nodeA bigBox:(CCNode *)nodeB