i was reading a tutorial from ray wenderlich website and i found this loop :
for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()) {
so here, b is overwritten? i find this a bit strange
and here’s the code :
for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()) {
if (b->GetUserData() != NULL) {
CCSprite *ballData = (CCSprite *)b->GetUserData();
ballData.position = ccp(b->GetPosition().x * PTM_RATIO,
b->GetPosition().y * PTM_RATIO);
ballData.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
}
}
thanks
Yes, b is overwritten. But b is just a pointer into a linked list of b2Body objects. The whole purpose of b is to point to each b2Body in the list, one at a time.