Note that there are some explanatory texts on larger screens.

plurals
  1. POtracking a 'body's' position after another body joint to it has been destroyed
    primarykey
    data
    text
    <p>I have created a revolute joint between two bodies. When a another body gets into contact (see Contacter.mm below) with one of them (body with tag ==90), I destroy the body with tag == 90. I put a CCLOG to track the sprite position of the revolute joint body that was not destroyed. The CCLOG works fine till it's joint body is destroyed. Then the CCLOG stops printing to the console. How can I solve this? Below is the relevant code.</p> <p>Contacter.mm:</p> <pre><code>#import "Contacter.h" #import "Box2D.h" @implementation Contacter @synthesize arrayOfBodies = _arrayOfBodies; @synthesize spriteToDestroy = _spriteToDestroy; -(void)destroyBodies:(b2Body*)body { _arrayOfBodies = [[NSMutableArray alloc] init]; NSValue *bodyValue = [NSValue valueWithPointer:body]; [_arrayOfBodies addObject:bodyValue]; } -(void)physicsSpritesContact:(CCPhysicsSprite*)onePhysicsSprite otherSprite (CCPhysicsSprite*)twoPhysicsSprite; { int firstTag = onePhysicsSprite.tag; int secondTag = twoPhysicsSprite.tag; if (((firstTag == 90) &amp;&amp; (secondTag == 101 )) || ((firstTag == 101) &amp;&amp; (secondTag == 90))) { if (tag1 == 90) { [self destroyBodies:onePhysicsSprite.b2Body];// adds body to array to be destroyed spriteToDestroy = onePhysicsSprite; // taking note of sprite to be destroyed } else if (tag2 == 90) { [self destroyBodies:twoPhysicsSprite.b2Body]; spriteToDestroy = twoPhysicsSprite; } } </code></pre> <p>The following method within HelloWorldLayer.mm is called in the update method to destroy the body and sprite with (tag == 90):</p> <pre><code>-(void)removeDestroyedBodiesAndSprites { if ([bodyContact arrayOfBodies]) { for (NSValue* bodyValue in [bodyContact arrayOfBodies]) { b2Body *removeBody; removeBody = (b2Body*)[bodyValue pointerValue]; world-&gt;DestroyBody(removeBody); removeBody = NULL; [self removeChild:[bodyContact spriteToDestroy]]; } } CCLOG(@"y value for Sam sprite %f",[Sam samPhysicsSprite].position.y); // here is the CCLOG } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload