How to get sprite to remove when collision detect with chipmuck physic

i created a sprite and add physicsbody for it
when collsion detect, i can’t get sprite from physicsbody to remove it

The collision detect function you registered has a PhysicsContact parameter. From it, you can retrieve the 2 sprites that are colliding, and do whatever you want on them:

bool HelloWorld::onContactBegin(PhysicsContact &contact)
{
Sprite * spriteA = (Sprite *) contact.getShapeA()->getBody()->getNode();
Sprite * spriteB = (Sprite *) contact.getShapeB()->getBody()->getNode();


}

2 Likes

Do you know how to get the Sprite from Body in Cocos2D JS using Chipmunk physics?