cocos2d iphone - How to destroy a body with CCPhysicsSprite -


i've realized ccphysicssprite different in few ways ccsprite. example, must set body before set position of sprite. believe 1 of these differences causing exc_bad_access error when try destroying body. call schedulesprite method in update method.

-(void)schedulesprite {  if ([testsprite physicssprite].b2body != null) { b2vec2 force = b2vec2(-5, 10.0 * [testsprite physicssprite].b2body->getmass()); [testsprite physicssprite].b2body->applyforce(force, [testsprite physicssprite].b2body->getworldcenter() );  if ([testsprite physicssprite].position.x < 0) { world->destroybody([testsprite physicssprite].b2body); [testsprite physicssprite].b2body = null;     } } } 

i exc_bad_access pointing line

b2vec2 pos  = _b2body->getposition(); 

in the

-(cgaffinetransform) nodetoparenttransform 

method, within class

ccphysicssprite.mm 

thanks.

despite destroyed body, sprite keep doing stuff, may remove sprite parent also, like.-

if ([testsprite physicssprite].position.x < 0) {     world->destroybody([testsprite physicssprite].b2body);     [[testsprite physicssprite] removefromparentandcleanup:yes]; } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -