问题
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?
回答1:
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'
来源:https://stackoverflow.com/questions/8951392/collision-detection-using-box2dfor-android