Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get b2Body of current CCSprite
    primarykey
    data
    text
    <p>In my code i've always used <code>spriteA = (__bridge CCSprite *) bodyA-&gt;GetUserData(); //where spriteA is a CCSprite and bodyA is a b2Body.</code> I use it to get whatever sprite is linked to bodyA. My problem is, how do I do this the other way around? I have a sprite and I want to find out what b2Body is linked to it. How do I do this?</p> <p><strong>Edit</strong></p> <p>I don't know wether I set it up right or not, but I'm trying to remove all b2bodies (and sprites) in an array called row4 once there are no more blue objects (objects in row4BlueArray) Here is part of the code in my tick method:</p> <pre><code>//Find the sprite for the b2Bodies else if (bodyA-&gt;GetUserData() != NULL &amp;&amp; bodyB-&gt;GetUserData() != NULL) { spriteA = (__bridge CCSprite *) bodyA-&gt;GetUserData(); spriteB = (__bridge CCSprite *) bodyB-&gt;GetUserData(); contactPositionX = spriteA.position.x; contactPositionY = spriteB.position.y; //If sprite is a member of row 4 (tag 400) if (spriteA.tag == 400 &amp;&amp; spriteB.tag == 8) { [self createExplosionBlue]; [self addTileScore]; [self removeChild:spriteA cleanup:YES]; [self removeChild:spriteB cleanup:YES]; NSLog(@"row 4 count: %d",row4BlueArray.count); //Remove object from another array [row4BlueArray removeLastObject]; toDestroy.insert(bodyA); toDestroy.insert(bodyB); [self unschedule:@selector(tick:)]; ballCount = 0; //if that array is empty, then remove all objects from this array (row4) if (row4BlueArray.count == 0) { for (b2Body * b = _world-&gt;GetBodyList(); b != NULL; b = b-&gt;GetNext()) { Box2DSprite * sprite = (__bridge Box2DSprite*) b-&gt;GetUserData(); b2Body * spriteBody = sprite.body; //not sure how to remove all bodies in an array (row4)` } } } </code></pre>
    singulars
    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