Hey, im programming for the iphone using box2d and cocos2d frameworks.
Currently, I have 3 Classes all subclasses of CCSprite.
They are: DynamicBlock1, DynamicBlock2 and DynamicEgg1
Basically my problem is that I want to separate the iterations in the tick method so that I can iterate certain classes and not others.
Currently the Tick (iteration) method is split into two parts, isMoving == YES/NO.. This switches the iteration between b2body(Master)-sprite(Slave) and b2body(Slave)-sprite(Master). This way I can delegate who controls who. And it works quite well.
Once again, the problem is that this code below, will iterate over ALL my bodies from all my classes in GetBodyList(). When I just want the iteration to occur to the one class (DynamicBlock1)...
Is there a way to do this? To isolate the iterations?
A thousand thank you's
Oliver
-(void) tick:(ccTime)dt
{
int32 velocityIterations = 8;
int32 positionIterations = 1;
world->Step(dt, velocityIterations, positionIterations);
for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
{
DynamicBlock1 *block1 = (DynamicBlock1*)b->GetUserData();
if (block1.isMoving == NO){
block1.position = CGPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO);
block1.rotation = -1 * CC_RADIANS_TO_DEGREES(b->GetAngle());
}
if (block1.isMoving == YES){
b2Vec2 b2Position = b2Vec2(block1.position.x/PTM_RATIO, block1.position.y/PTM_RATIO);
float32 b2Angle = -1 * CC_DEGREES_TO_RADIANS(block1.rotation);
b->SetTransform(b2Position,b2Angle);
}
}
}