i have a world in cocos2d with box2d, that has a gravity. now in order to add a body for each sprite, i am calling a function and send her the sprite.
sprite1, has to move according to gravity, but sprite2 has to be static,without gravity, just until sprite1 hit it,then the world forces should affect him.
how do i set only sprite1/body gravity to be zero 'til the other sprite hit him ?
my problem is that all sprites using the same function for the body:
- (void)addBoxBodyForSprite:(CCSprite *)sprite {
b2BodyDef spriteBodyDef;
spriteBodyDef.type = b2_dynamicBody;
spriteBodyDef.position.Set(sprite.position.x/PTM_RATIO,sprite.position.y/PTM_RATIO);
spriteBodyDef.userData = sprite;
spriteBody = world->CreateBody(&spriteBodyDef);
b2PolygonShape spriteShape;
spriteShape.SetAsBox(sprite.contentSize.width/PTM_RATIO/2,sprite.contentSize.height/PTM_RATIO/2);
b2FixtureDef spriteShapeDef;
spriteShapeDef.shape = &spriteShape;
spriteShapeDef.density = 10.0;
spriteShapeDef.isSensor = true;
spriteBody->CreateFixture(&spriteShapeDef);
}
i want to apply gravity at the start only on sprite1, BUT i do want to create a body for sprite2 also, because later it will be affected by the world.
so, after create 2 bodies at start, how do i stop only sprite2 from falling ?
thanks a lot.