cpMouse Implementation Problems
Posted: Sat Nov 14, 2009 9:41 pm
I implemented the cpMouse code into my project. There are no errors or warnings, but when I run the program it quits and the console reads "Assertion fail: (body != NULL), function cpShapeInit."
Here is my code:
extern void makeStaticBox(float x, float y, float width, float height);
cpSpace *space;
cpBody *staticBody
...
Sprite *Block1 = [[Sprite spriteWithFile:@"1x1.png"] retain];
Block1.position = cpv(160,240);
[self addChild: Block1];
cpVect verts[] = {
cpv(-36,-36),
cpv(-36, 36),
cpv(36, 36),
cpv(36,-36),
};
cpBody *Block1Body = cpBodyNew(50.0f, INFINITY);
Block1Body->p = cpv(160,240);
Block1Body->v = cpv(0, 0);
cpSpaceAddBody(space, Block1Body);
cpShape * Block1Shape = cpPolyShapeNew(Block1Body, 4, verts, cpvzero);
Block1Shape->e = 0.9f;
Block1Shape->u = 0.9f;
Block1Shape->data = Block1;
Block1Shape->collision_type = 0;
cpSpaceAddShape(space, Block1Shape);
CGSize s = [[Director sharedDirector] winSize];
int margin = 4;
int dmargin = margin*2;
makeStaticBox(margin, margin, s.width - dmargin, s.height - dmargin); //This references a static box the size of the window in a C class.
}
return self;
}
Please help!
Here is my code:
extern void makeStaticBox(float x, float y, float width, float height);
cpSpace *space;
cpBody *staticBody
...
Sprite *Block1 = [[Sprite spriteWithFile:@"1x1.png"] retain];
Block1.position = cpv(160,240);
[self addChild: Block1];
cpVect verts[] = {
cpv(-36,-36),
cpv(-36, 36),
cpv(36, 36),
cpv(36,-36),
};
cpBody *Block1Body = cpBodyNew(50.0f, INFINITY);
Block1Body->p = cpv(160,240);
Block1Body->v = cpv(0, 0);
cpSpaceAddBody(space, Block1Body);
cpShape * Block1Shape = cpPolyShapeNew(Block1Body, 4, verts, cpvzero);
Block1Shape->e = 0.9f;
Block1Shape->u = 0.9f;
Block1Shape->data = Block1;
Block1Shape->collision_type = 0;
cpSpaceAddShape(space, Block1Shape);
CGSize s = [[Director sharedDirector] winSize];
int margin = 4;
int dmargin = margin*2;
makeStaticBox(margin, margin, s.width - dmargin, s.height - dmargin); //This references a static box the size of the window in a C class.
}
return self;
}
Please help!