As the error message states, you need to implement a post-step callback. To do this on Cocos2d 3.0 and with Objective Chipmunk you first need to import a new header file to access advanced chipmunk properties:
#import "CCPhysics+ObjectiveChipmunk.h"
Then add the callback in your collision handler:
-(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair static:(CCNode *)nodeA wildcard:(CCNode *)nodeB
{
[[_physicsNode space] addPostStepBlock:^{
_player.physicsBody.type = CCPhysicsBodyTypeStatic;
} key:_player];
}
Note that I assume you have access to your CCPhysicsNode in _physicsNode
.
The Chipmunk Space of CCPhysicsNode
is locked while the a physics step is calculated. During a calculation of a step collisions are resolved and objects are moved around - changing the body type during this calculation could result in unexpected behaviour.
Therefore you add the postStepBlock
callback. This is a place where a body type can be safely changed.
The key
value you pass into the callback is used to ensure that the code is only called once (especially useful when removing objects, but it also makes sense in this case).
If also added an example implementation: https://www.makegameswith.us/gamernews/367/make-a-dynamic-body-static-in-cocos2d-30-with-chi