callback - How to make a dynamic body static in Cocos2d v3.0 with Chipmunk -


i’m using cocos2d v3 , want change body dynamic static after colliding body. @ moment i’ve got:

-(void)ccphysicscollisionpostsolve:(ccphysicscollisionpair *)pair static:(ccnode *)nodea wildcard:(ccnode *)nodeb {    _player.physicsbody.type = ccphysicsbodytypestatic; } 

or

-(bool)ccphysicscollisionpresolve:(ccphysicscollisionpair *)pair static:(ccnode *)nodea wildcard:(ccnode *)nodeb {    _player.physicsbody.type = ccphysicsbodytypestatic;    return yes; } 

but neither works. error:

aborting due chipmunk error: operation cannot done safely during call cpspacestep() or during query. put these calls post-step callback. failed condition: !space->locked

i tried make joint @ point of collision doesn’t work right.

is there way change body dynamic collides in v3? can in later versions using box2d. want stop gravity , other forces doesn’t move. want make stuck surface.

read little on post-step callbacks i'm unfamiliar how use them.

any appreciated.

as error message states, need implement post-step callback. on cocos2d 3.0 , objective chipmunk first need import new header file access advanced chipmunk properties:

#import "ccphysics+objectivechipmunk.h" 

then add callback in collision handler:

-(void)ccphysicscollisionpostsolve:(ccphysicscollisionpair *)pair static:(ccnode *)nodea wildcard:(ccnode *)nodeb {     [[_physicsnode space] addpoststepblock:^{         _player.physicsbody.type = ccphysicsbodytypestatic;     } key:_player]; } 

note assume have access ccphysicsnode in _physicsnode. chipmunk space of ccphysicsnodeis locked while physics step calculated. during calculation of step collisions resolved , objects moved around - changing body type during calculation result in unexpected behaviour.

therefore add poststepblockcallback. place body type can safely changed.

the key value pass callback used ensure code called once (especially useful when removing objects, makes sense in case).

if added example implementation: https://www.makegameswith.us/gamernews/367/make-a-dynamic-body-static-in-cocos2d-30-with-chi


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -