在我的代码中,我一直spriteA = (__bridge CCSprite *) bodyA->GetUserData(); //where spriteA is a CCSprite and bodyA is a b2Body.
使用它来获取与 bodyA 相关联的任何精灵。我的问题是,我该怎么做呢?我有一个精灵,我想找出 b2Body 与它相关联的内容。我该怎么做呢?
编辑
我不知道我是否设置正确,但是一旦没有更多蓝色对象(row4BlueArray 中的对象),我正在尝试删除名为 row4 的数组中的所有 b2bodies (和精灵) 这是代码的一部分在我的勾选方法中:
//Find the sprite for the b2Bodies
else if (bodyA->GetUserData() != NULL && bodyB->GetUserData() != NULL) {
spriteA = (__bridge CCSprite *) bodyA->GetUserData();
spriteB = (__bridge CCSprite *) bodyB->GetUserData();
contactPositionX = spriteA.position.x;
contactPositionY = spriteB.position.y;
//If sprite is a member of row 4 (tag 400)
if (spriteA.tag == 400 && 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->GetBodyList(); b != NULL; b = b->GetNext()) {
Box2DSprite * sprite = (__bridge Box2DSprite*) b->GetUserData();
b2Body * spriteBody = sprite.body;
//not sure how to remove all bodies in an array (row4)`
}
}
}