gpt4 book ai didi

java - LIBGDX 加速整个游戏(使用 box2d)

转载 作者:行者123 更新时间:2023-11-29 03:26:13 25 4
gpt4 key购买 nike

我想知道如何使用 libgdx 加快整个游戏的速度(例如在单击按钮后)。我在游戏中的方法是修改

中使用的时间步长变量
world.step(TIMESTEP, VELOCITYITERATIONS, POSITIONITERATIONS);

但我现在确定这是否是个好主意。有没有更好的方法来存档?

最佳答案

使用 Box2D 时,您可以通过修改物理步骤来加快游戏速度。一个问题是您应该使用恒定的步进时间。我在我的游戏中使用以下代码:

private float accumulator = 0;

private void doPhysicsStep(float deltaTime) {
// fixed time step
// max frame time to avoid spiral of death (on slow devices)
float frameTime = Math.min(deltaTime, 0.25f);
accumulator += frameTime;
while (accumulator >= Constants.TIME_STEP) {
WorldManager.world.step(Constants.TIME_STEP, Constants.VELOCITY_ITERATIONS, Constants.POSITION_ITERATIONS);
accumulator -= Constants.TIME_STEP;
}
}

这确保您的步进时间是恒定的,但它与渲染循环同步。您可以使用它并将其称为doPhysicsStep(deltaTime * speedup)(默认情况下加速为 1,按下按钮后可能为 1.5)。这可能会导致不是最佳结果,但您可以试一试。

否则,您可以按照评论中的建议采取艰难的方式,并通过修改代码中必要的每个地方来投入更多时间(所有力量都需要修改,在许多情况下这并不像force * speedup,因为在真实/物理世界中,并非所有事物都是线性的)。

关于java - LIBGDX 加速整个游戏(使用 box2d),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20848442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com