It's the first time that I have to use constraints, but I get an error when I add the joint to the space.
Can you please help me to find what's wrong!?
Thank you!
Code: Select all
///METHODS TO CREATE BODIES
- (void)createDinamicBody:(cpBody*)body AtLocation:(CGPoint)location {
float boxSize = 60.0;
float mass = 1.0;
body = cpBodyNew(mass, cpMomentForBox(mass, boxSize, boxSize));
body->p = location;
cpSpaceAddBody(space, body);
shapeDinamic = cpBoxShapeNew(body, boxSize, boxSize);
shapeDinamic->e = 1.0;
shapeDinamic->u = 1.0;
shapeDinamic->data = box_img;
cpSpaceAddShape(space, shapeDinamic);
NSLog(@"DINAMIC");
}
- (void)createStaticBody:(cpBody*)body AtLocation:(CGPoint)location{
body = cpBodyNew(INFINITY, INFINITY);
body->p = location;
shapeStatic = cpBoxShapeNew(body, 60, 40);
shapeStatic->data = slider_img;
cpSpaceAddStaticShape(space, shapeStatic);
NSLog(@"STATIC");
}
///MAIN, NOTE: I POST ONLY THE INTERESTING CODE
[self createDinamicBody:box AtLocation:ccp(240, 160)];
[self createStaticBody:slider AtLocation:ccp(240, 250)];
cpConstraint* joint = cpGearJointNew(box, slider, 0.5, 0.5);
cpSpaceAddConstraint(space, joint); /// THIS IS THE LINE OF THE ERROR!!!!!
------
i get this error:
/// Returns true if the body has not been added to a space.
static inline cpBool cpBodyIsRogue(const cpBody *body)
{
return (body->CP_PRIVATE(space) == ((cpSpace*)0));
}
I've also another question: can I move manually the static body if I've decleared it in this way?? ...I cant understand the difference between static and rogue body...
Than you again!