LIBGDX - 尸体在 Android 上慢慢地 运行 掉落,但在桌面上没有
LIBGDX - Bodies falling down and running slowly on Android but not in desktop
我发现了这个问题:
进行了更改但仍然无效。
相关代码如下:
相机
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);
问题已通过更改时间步解决。多亏了评论,我才弄明白。
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 是一篇详细解释会发生什么以及如何解决这类非常常见的问题的文章。
我发现了这个问题:
相关代码如下:
相机
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);
问题已通过更改时间步解决。多亏了评论,我才弄明白。
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 是一篇详细解释会发生什么以及如何解决这类非常常见的问题的文章。