[Box2D] Get CCSprite from b2Contact

[Box2D] Get CCSprite from b2Contact
0.0 0


How i can get a CCSprite instance from b2Contact?

void StarContactListener::EndContact(b2Contact* contact)
    bool A = (contact->GetFixtureA()->GetUserData() != NULL);
    bool B = (contact->GetFixtureB()->GetUserData() != NULL);
    CCLog("Collision detected.");



Hello, 4idor,

My CCSprite object linked with b2Body and I have code like this:

b2Body* bodyA = contact~~>GetFixtureA~~>GetBody;
b2Body* bodyB = contact~~>GetFixtureB~~>GetBody;
CCSprite* spriteA = bodyA~~>GetUserData;
CCSprite* spriteB = bodyB~~>GetUserData();

Hope it helps.



Hi Dmitry,

It works for me, so big thanks to you!