Say I create my world in box2d, then create a Hero on screen as well. Something like this:
[self SetUpWorld:winSize];
[self addHero];
Where SetUpWorld creates a normal box2d world, and addHero adds a CCSprite, B2body, fixture, etc.
Then i run my tick like the following:
world->Step(dt, 10, 8);
for(b2Body* b = world->GetBodyList();b;b=b->GetNext())
{
if(b->GetUserData()!=NULL)
{
CCSprite* sprite = (CCSprite*)b->GetUserData();
sprite.position = CGPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO);
sprite.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
[self Scroll:sprite.position];
}
}
This allows me to move my hero and scroll him. Now, say I move and scroll my hero to a point that I no longer need him and want to scroll a different hero. So I add another hero to my world with the same method ([self addHero];). However the problem is that box2d is still 'scrolling' with my original hero. Is there a way to change bodies? Or maybe iterate through the world to get the new hero?