I have just decided to create a NSObject to house AtlasSprite Coords, body/shape and a few other variables for a ball object. which has worked great and made things a lot tidier in my layer class.
but now i am using the chipmunk callback functions and im stuck!! im not sure how to retrieve the ball instance that a shape belongs to so that i can release it..
any advice on how you guys go about organising shapes/sprites and bodies would be great.. is it even worth having a ball class?
here is my code so you know what im trying to do.
static void
removeBall(cpSpace *space, cpShape *shape, void *unused) {
cpSpaceRemoveBody(space, shape->body);
cpBodyFree(shape->body);
AtlasSprite *sprite = shape->data;
[sprite.parent removeChild:sprite cleanup:YES];
cpSpaceRemoveShape(space, shape);
cpShapeFree(shape);
//[ball release];
}
static void
matchedBallPost(cpArbiter *arb, cpSpace *space, void *unused) {
cpShape *a, *b; cpArbiterGetShapes(arb, &a, &b);
cpSpaceAddPostStepCallback(space, (cpPostStepFunc)removeBall, b, NULL);
}
Thanks
Byron