简体   繁体   English

使用Box2d进行碰撞检测(适用于Android)?

[英]Collision Detection using Box2d(for Android)?

Can someone explain the in what way works the collision detection using box2d for android. 有人可以解释使用box2d为android进行碰撞检测的方式。 I cannot understand in what way works BBContactListener. 我无法理解以什么方式工作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? 我应该延长标准来创造我自己的或如何?

I did not use box2d for android, but I think the idea is the same there. 我没有使用box2d用于android,但我认为这个想法是一样的。 You have to implement contact processing methods. 您必须实现联系处理方法。 That's the way to do it in C++. 这是在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' 然后把这个班级传给'b2World'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM