我正在使用JBox2d来进行游戏项目中的碰撞检测。我用静态刚体表示世界上的障碍物。每当动态刚体(即游戏角色)与其中一个障碍物发生碰撞时,性能会显著下降。帧率将从 ~120 降至 ~5。似乎在静态刚体的角落发生碰撞时更频繁出现这种情况。
当我将世界障碍物的刚体类型设置为动态而不是静态,并设置非常高的密度(以防止在碰撞时移动刚体)时,这个问题消失了...但是,这个解决方案并不适合我的情况......
有什么想法可以解决这个巨大的帧率下降吗?
以下是我用来创建静态刚体的代码:
当我将世界障碍物的刚体类型设置为动态而不是静态,并设置非常高的密度(以防止在碰撞时移动刚体)时,这个问题消失了...但是,这个解决方案并不适合我的情况......
有什么想法可以解决这个巨大的帧率下降吗?
以下是我用来创建静态刚体的代码:
BodyDef def = new BodyDef();
def.type = BodyType.STATIC; // If this line is commented and the other
//commented lines are uncommented, the issue goes away.
//def.type = BodyType.DYNAMIC;
def.position.set(worldBounds.getCenterX(), worldBounds.getCenterY());
Body staticBody = b2World.createBody(def);
PolygonShape box = new PolygonShape();
box.setAsBox(worldBounds.getWidth() * 0.5f, worldBounds.getHeight() * 0.5f);
FixtureDef fixture = new FixtureDef();
fixture.shape = box;
fixture.friction = 0.3f;
//fixture.density = 1000000000;
staticBody.createFixture(fixture);
//staticBody.setSleepingAllowed(true);
//staticBody.setFixedRotation(true);
我尝试使用CircleShape而不是PolygonShape,但这并没有帮助解决问题。
谢谢!