当任何2个实体相互接触时,不会调用此联系脚本。我曾尝试在任何物体接触时简单地调用该方法,但这也不起作用。
world.setContactListener(new ContactListener() {
@Override
public void beginContact(Contact contact) {
Fixture f1 = contact.getFixtureA();
Fixture f2 = contact.getFixtureB();
Body b1 = f1.getBody();
Body b2 = f2.getBody();
if((b1.getUserData() == "player" && b2.getUserData() == "Enemy") || (b1.getUserData() == "player" && b2.getUserData() == "Enemy")) {
player.death();
hud.death();
}
}
@Override
public void endContact(Contact contact) {
}
@Override
public void preSolve(Contact contact, Manifold oldManifold) {
}
@Override
public void postSolve(Contact contact, ContactImpulse impulse) {
}
});
答案 0 :(得分:0)