LIBGDX-实体掉落并在Android上运行缓慢,但在台式机上运行缓慢

时间:2018-08-14 13:36:40

标签: android libgdx game-engine

我发现了这个问题:body falls slowly in any gravity 进行了更改,但仍然无法正常工作。

这是相关代码:

对于相机

float w = (float) Gdx.graphics.getWidth();
    float h = (float) Gdx.graphics.getHeight();

    //Initialize variables
   camera = new OrthographicCamera();
    viewport = new FitViewport(w/ PPM,h/ PPM,camera);
   //set the position of the camera to the center of the world
    camera.position.set(viewport.getWorldWidth()/2, viewport.getWorldHeight()/2,0);

创造世界

 world = new World(new Vector2(0,-24),true);

创造身体

 BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(300
            /JungleMasters.PPM,3000/JungleMasters.PPM);

    b2body = world.createBody(bodyDef);

世界脚步代码

  world.step(1 / 60f, 6, 2);

1 个答案:

答案 0 :(得分:1)

通过更改时间步解决了问题。多亏了这些评论,我才得以弄清楚。

  private static final float STEP_TIME = 1/60f;
private float accumulator = 0;

private void stepWorld() {
    float delta = Gdx.graphics.getDeltaTime();

    accumulator += Math.min(delta, 0.25f);

    while (accumulator >= STEP_TIME) {
        accumulator -= STEP_TIME;

        world.step(STEP_TIME, 10, 8);
    }
}

This是一篇文章,详细介绍了发生的情况以及如何解决此类问题,这是很常见的。