Code: Select all
for (i = 0; i<[gameController.game.currentLevel.monsterArray count]; i++) {
Monster * monster = [gameController.game.currentLevel.monsterArray objectAtIndex:i];
//cpSpaceRemoveConstraint(space, monster.pivot);
//cpSpaceRemoveConstraint(space, monster.gear);
cpSpaceAddPostStepCallback(space, (cpPostStepFunc)postStepConstraintRemove, monster.pivot, NULL);
cpSpaceAddPostStepCallback(space, (cpPostStepFunc)postStepConstraintRemove, monster.gear, NULL);
cpSpaceAddPostStepCallback(space, (cpPostStepFunc)postStepActiveShapeRemove, monster.view, NULL);
cpSpaceAddPostStepCallback(space, (cpPostStepFunc)postStepActiveRemove, monster.shape, NULL);
cpBodyFree(monster.controlBody);
[monster.sprite removeFromParentAndCleanup:YES];
[monster.shadow removeFromParentAndCleanup:YES];
}
the commented part is what I was using in chipmunk 5. My objects are similar to the objects in tank demo. I just added a sensor shape to act as the monsters view.
and these are the post-step functions
Code: Select all
static void postStepActiveRemove(cpSpace *space, cpShape *shape, void *unused)//removes body and shape
{
cpSpaceRemoveBody(space, shape->body);
cpBodyFree(shape->body);
cpSpaceRemoveShape(space, shape);
cpShapeFree(shape);
}
static void postStepConstraintRemove(cpSpace *space, cpConstraint *constraint, void *unused)
{
cpSpaceRemoveConstraint(space, constraint);
}
static void postStepActiveShapeRemove(cpSpace *space, cpShape *shape, void *unused)//removes shape only
{
cpSpaceRemoveShape(space, shape);
cpShapeFree(shape);
}