Sprites not totally removed from screen
Posted: Wed Jan 27, 2010 6:33 pm
Hi there,
I have a problem about some sprite images not totally remove when I call the collision handler:
static void
postStepRemove(cpSpace *space, cpShape *shape, void *data)
{
HelloWorld *mb = (HelloWorld*) data;
[mb explode:shape->body->p.x y:shape->body->p.y];
cpSpaceRemoveBody(space, shape->body);
cpBodyFree(shape->body);
cpSpaceRemoveShape(space, shape);
cpShapeFree(shape);
}
static int
begin(cpArbiter *arb, cpSpace *space, void *data)
{
cpShape *a, *b; cpArbiterGetShapes(arb, &a, &b);
cpSpaceAddPostStepCallback(space, (cpPostStepFunc)postStepRemove, b, data);
return 0;
}
and I bind the collision handler in my init method of my game CCLayer using this,
cpSpaceAddCollisionHandler(space, 2, 2, begin, NULL, NULL, NULL, self);
What I actually want is that when two non-static shapes collide, the other one will be removed from the scene. What happened is that, there are instances that when the 2 objects collide, the sprite of the other shape object remained on screen. Yet there are instances that it's doing exactly as what I expected.
Anyone who can give me some insights about this?
Thanks in advance!
I have a problem about some sprite images not totally remove when I call the collision handler:
static void
postStepRemove(cpSpace *space, cpShape *shape, void *data)
{
HelloWorld *mb = (HelloWorld*) data;
[mb explode:shape->body->p.x y:shape->body->p.y];
cpSpaceRemoveBody(space, shape->body);
cpBodyFree(shape->body);
cpSpaceRemoveShape(space, shape);
cpShapeFree(shape);
}
static int
begin(cpArbiter *arb, cpSpace *space, void *data)
{
cpShape *a, *b; cpArbiterGetShapes(arb, &a, &b);
cpSpaceAddPostStepCallback(space, (cpPostStepFunc)postStepRemove, b, data);
return 0;
}
and I bind the collision handler in my init method of my game CCLayer using this,
cpSpaceAddCollisionHandler(space, 2, 2, begin, NULL, NULL, NULL, self);
What I actually want is that when two non-static shapes collide, the other one will be removed from the scene. What happened is that, there are instances that when the 2 objects collide, the sprite of the other shape object remained on screen. Yet there are instances that it's doing exactly as what I expected.
Anyone who can give me some insights about this?
Thanks in advance!