views:

122

answers:

1

First, sorry for my English, im not an American. My question is how can I remove the shape and body from the space, this isn't related with collision detection. Im triying to do this with a touch event, specifically I'm trying to clear a ball Touching it (I have a lot of balls in the space), but I have no idea how to do it, I have been looking on Internet and cannot find any help regarding how to do it, all relates to the collisions and that's not what I need.

I read many times the documentation, but not contain any useful information how to do this. Only have how delete with colission. I know how delete with colission:

static void postStepRemove (cpSpace *space, cpShape *shape, void *data) {

//Remove the shape and body
cpSpaceRemoveBody(space, shape->body);
cpBodyFree(shape->body);
cpSpaceRemoveShape(space, shape);
cpShapeFree(shape);

}

static int collission(cpArbiter *arb, cpSpace *space, void *data){

     cpShape *a, *b;

 cpArbiterGetShapes(arb, &a, &b);

    cpSpaceAddPostStepCallback(space, (cpPostStepFunc)postStepRemove, a, nil);
    cpSpaceAddPostStepCallback(space, (cpPostStepFunc)postStepRemove, b, nil);
    return 0;
}
return 1;

}

I use this with collision, but I need some example without collision.

A: 

Find the library documentation and read the damn manual: Chipmunk physics documentation

cpBodyFree and cpShapeFree seem to be the API calls you need. Cocos2d likely has some bindings on calling them. Locate Cocos2D documentation if you need to know more about those calls.

Cheery
Yes I know, but I read many times the documentation, but not contain any useful information how to do this. Only have how delete with colission.
Xenetrix
Also I cannot remove a shape and body when cpSpaceStep is running. I need a post step remove but I dont know how to do this.
Xenetrix
just create a set for shapes you'll remove after cpSpaceStep has completed. `dropped_shapes.add(shape)`, then free each shape added into that set once cpSpaceStep completes.
Cheery