Collision Detection using Box2d(for Android)?

这一生的挚爱 提交于 2019-12-22 08:57:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!