我正在尝试使用Box2d实现单向平台。这是我的代码:
public void preSolve(Contact contact, Manifold oldManifold) {
Fixture platform = null;
Fixture ranger = null;
Fixture fa = contact.getFixtureA();
Fixture fb = contact.getFixtureB();
if (BodyUtils.isPlatform(fa.getBody()) && BodyUtils.isRanger(fb.getBody())) {
platform = fa;
ranger = fb;
} else if (BodyUtils.isPlatform(fb.getBody()) && BodyUtils.isRanger(fa.getBody())) {
platform = fb;
ranger = fa;
}
if (platform == null) return;
Body platformBody = platform.getBody();
Body rangerBody = ranger.getBody();
int rangerTopY = (int) (rangerBody.getPosition().y + ((RangerUserData)rangerBody.getUserData()).getHeight() - 0.5f);
int platformBottomY = (int) platformBody.getPosition().y;
if (rangerTopY == platformBottomY) {
contact.setEnabled(false);
}
}
问题是contact.setEnabled(false)
已调用但无效。为什么会这样?