GeorgeBuron
GeorgeBuron

Reputation: 45

Collision Detection using Box2d(for Android)?

Can someone explain the in what way works the collision detection using box2d for android. I cannot understand in what way works BBContactListener.

BBContactListener listener = new BBContactListener();
world = new BBWorld(gravity, doSleep);
world.SetContactListener(listener);

How to use that listener? Should I extend standart to create my own or how?

Upvotes: 4

Views: 979

Answers (1)

Andrew
Andrew

Reputation: 24846

I did not use box2d for android, but I think the idea is the same there. You have to implement contact processing methods. That's the way to do it in C++.

class ContactListener : public b2ContactListener
{
public:
    ContactListener();
    ~ContactListener();

    void BeginContact(b2Contact *contact) {...}
    void EndContact(b2Contact *contact) {...}
    void PreSolve (b2Contact *contact, const b2Manifold *oldManifold) {...}
    void PostSolve (b2Contact *contact, const b2ContactImpulse *impulse) {...}
};

Then just pass this class to `b2World'

Upvotes: 1

Related Questions