Just trying to wrap my head around an issue I am experiencing with setting the position of individual bodies in an existing Chipmunk space. Here is the scenario in greater detail:
I am working on a skeletal animation + ragdoll creation engine that can be used in lots of different applications. To create a new character of type CCNode, I do the following:
Code: Select all
// Gameplay.m
...
Character* ninja = [Character characterFromConfigFile:@"ninja-v1.xml"];
// Pass in the space I wish to add the ragdoll to (ragdoll.m)
[ninja createRagdollWithSpace:space];
[ninja setPosition:ccp(200,200)];
// Ninja is a CC2d node, add it to the scene in Gameplay.m
[self addChild:ninja];
...
// Create the floor / platform
cpBody* floorBody = cpBodyNewStatic(1000.0, INFINITY);
floorBody->p = ccp(0, 0);
cpVect verts[] = { cpv(0.0, 50.0), cpv(400.0, 50.0), cpv(480.0, 0.0), cpvzero };
cpShape* floorShape = cpPolyShapeNew(floorBody, 4, verts, cpvzero);
floorShape->collision_type = GROUND_COLLISION_TYPE;
cpSpaceAddBody(space, floorBody);
cpSpaceAddStaticShape(space, floorShape);
...
Code: Select all
// For each body part specified in the config XML file, I loop through this code snippet:
-(void) createRagdollWithSpace:(cpSpace*) _space {
...
cpBodySetAngle(body, -CC_DEGREES_TO_RADIANS(rot));
cpSpaceAddBody(_space, body);
cpSpaceAddShape(_space, shape);
...
}
Code: Select all
[ninja setPosition:ccp(200,200)];
Any ideas on how to fix this?
Thanks!
-G.