我真的坚持这一点,我可以成功检测到碰撞,但我不能让参与碰撞的两个物体粘在一起。
这是我的ContactListener
world.setContactListener(listener);
listener = new ContactListener() {
@Override
public void preSolve(Contact contact, Manifold oldManifold) {
}
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
}
//called when two fixtures cease to touch
@Override
public void endContact(Contact contact) {
Fixture fixtureA = contact.getFixtureA();
Fixture fixtureB = contact.getFixtureB();
Gdx.app.log("beginContact", "between" + fixtureA.toString() + "and" + fixtureB.toString());
}
//called when two fixtures begin to touch
@Override
public void beginContact(Contact contact) {
Fixture fixtureA = contact.getFixtureA();
Fixture fixtureB = contact.getFixtureB();
Gdx.app.log("beginContact", "between" + fixtureA.toString() + "and" + fixtureB.toString());
}
};
这也是我在 world.step() 行之后直接放入我的 render() 的内容
int numContacts = world.getContactCount();
if(numContacts > 0)
{
Gdx.app.log("contact", "start of contact list");
for(Contact contact: world.getContactList())
{
Fixture fixtureA = contact.getFixtureA();
Fixture fixtureB = contact.getFixtureB();
Gdx.app.log("contact", "between" + fixtureA.toString() + "and" + fixtureB.toString());
}
Gdx.app.log("contact", "end of contact list");
}
我非常困惑于在后解决或预解决上放置什么真的很困惑。我遵循 iforce2d 粘性弹丸http://www.iforce2d.net/b2dtut/sticky-projectiles但我不懂 C++,并且在 Eclipse 中工作时遇到很多语法错误。请有人给我看一个工作碰撞的示例代码,请在java中碰撞后身体粘在一起。