Andengine Collision未检测到

时间:2015-06-11 16:04:45

标签: android box2d andengine

我创建了一个玩家矩形和一个敌人矩形,它创建了应该碰撞的矩形体,并且应该调用联系人监听器的beginContact()方法。不知道为什么它不被称为:/

D1

}

1 个答案:

答案 0 :(得分:0)

因为它有点复杂。它应该是这样的:

private ContactListener createContactListener()
{
ContactListener contactListener = new ContactListener()
{
    @Override
    public void beginContact(Contact contact)
    {
        final Fixture x1 = contact.getFixtureA();
        final Fixture x2 = contact.getFixtureB();

        if (x2.getBody().getUserData().equals("player")&&x1.getBody().getUserData().equals("monster"))
        {
        Log.i("CONTACT", "BETWEEN PLAYER AND MONSTER!");
        }
    }

    @Override
    public void endContact(Contact contact)
    {

    }

    @Override
    public void preSolve(Contact contact, Manifold oldManifold)
    {

    }

    @Override
    public void postSolve(Contact contact, ContactImpulse impulse)
    {

    }
};
return contactListener;

}

在这里您可以找到更多信息: http://www.matim-dev.com/handling-collisions-between-bodies.html