Hello
I don't think this is a Chipmunk or SpaceManager question really, but it's based around physics so I put it here, feel free to move if required.
After much forum use, and a huge amount of help from MobileBros I have a class which creates multiple chipmunk shapes, ties tem together with pins and constraints, and adds tem to my game layer. This is nice.
But, I now wish to control that object with impulses and forces. My header:
@interface trainerBody : CCNode {
}
-(id)initTBody:(int)kType :(int)flag :(CGPoint)offset spaceManager:(SpaceManager*)smgr;
@end
and Main:
@implementation trainerBody
-(id)initTBody:(int)kType :(int)flag :(CGPoint)offset spaceManager:(SpaceManager*)smgr {
[super init];
if(self != nil) {
cpShape *_landerBody = [smgr addRectAt:ccpAdd(offset, ccp(0, 8)) mass:18 width:20 height:25 rotation:0];
cpShape *_leftLeg = [smgr addRectAt:ccpAdd(offset, ccp(-15, -5)) mass:2 width:5 height:22 rotation:CC_DEGREES_TO_RADIANS(-45)];
cpShape *_rightLeg = [smgr addRectAt:ccpAdd(offset, ccp(15, -5)) mass:2 width:5 height:22 rotation:CC_DEGREES_TO_RADIANS(45)];
cpShape *_thruster = [smgr addRectAt:ccpAdd(offset, ccp(0, -3)) mass:3 width:14 height:8 rotation:0];
cpCCSprite *_landerBodyS = [cpCCSprite spriteWithShape:_landerBody file:@"ppBody.png"];
cpCCSprite *_leftLegS = [cpCCSprite spriteWithShape:_leftLeg file:@"ppLeftLeg.png"];
cpCCSprite *_rightLegS = [cpCCSprite spriteWithShape:_rightLeg file:@"ppRightLeg.png"];
cpCCSprite *_thrusterS = [cpCCSprite spriteWithShape:_thruster file:@"ppThruster.png"];
[smgr addPivotToBody:_landerBody->body fromBody:_leftLeg->body worldAnchor:cpvadd(offset, cpv(-5, 5))];
[smgr addPivotToBody:_landerBody->body fromBody:_rightLeg->body worldAnchor:cpvadd(offset, cpv(5, 5))];
[smgr addPivotToBody:_landerBody->body fromBody:_thruster->body worldAnchor:cpvadd(offset, cpv(0, 2))];
cpConstraint *gear = [smgr addGearToBody:_landerBody->body fromBody:_leftLeg->body phase:CC_DEGREES_TO_RADIANS(-45) ratio:1];
gear->maxForce = 5800;
cpConstraint *gear2 = [smgr addGearToBody:_landerBody->body fromBody:_rightLeg->body phase:CC_DEGREES_TO_RADIANS(45) ratio:1];
gear2->maxForce = 5800;
cpConstraint *thrustGear = [smgr addGearToBody:_landerBody->body fromBody:_thruster->body ratio:1];
thrustGear->maxForce = 2000;
_landerBody->group = flag;
_leftLeg->group = flag;
_rightLeg->group = flag;
_thruster->group = flag;
_landerBody->collision_type = kType;
_leftLeg->collision_type = kType;
_rightLeg->collision_type = kType;
[self addChild:_landerBodyS z:10];
[self addChild:_leftLegS z:9];
[self addChild:_rightLegS z:9];
[self addChild:_thrusterS z:9];
} return self;
}
@end
and implementation:
tb = [[trainerBody alloc] initTBody:1 :4 :ccp(200, 200) spaceManager:smgr];
[gameLayer addChild:tb];
Now I need to apply and reset forces on the _landerBodyS cpCCSprite, as well as set kCollisionTypes. This is where the general coding question comes in, how do I access _landerBodyS to apply forces to it, once it's in this class?
Regards.