我正在使用 libgdx 和 box2d 开发一款 Android 游戏。我的问题是 box2d 中身体的插值效果不佳......身体有点滞后。没有插值,身体“更少滞后”。这是我的代码的一部分:
public void gameRunning()
{
mAccumulator += Gdx.graphics.getDeltaTime();
if(mAccumulator > 1f)
{
mAccumulator = 1f;
}
while(mAccumulator >= BOX_STEP)
{
resetSmooth();
mWorld.step(BOX_STEP, BOX_VELOCITY_ITERATIONS, BOX_POSITION_ITERATIONS);
mAccumulator -= BOX_STEP;
}
mWorld.clearForces();
smooth();
}
public void smooth()
{
float ratio = mAccumulator/BOX_STEP;
float oneMinusRatio = 1.f-ratio;
mSmoothedX = ratio*mBowl.getPosition().x+oneMinusRatio*mPreviousX;
mSmoothedY = ratio*mBowl.getPosition().y+oneMinusRatio*mPreviousY;
mBowl.setTransform(mSmoothedX, mSmoothedY, 0f);
}
public void resetSmooth()
{
mSmoothedX = mPreviousX;
mSmoothedY = mPreviousY;
mPreviousX = mBowl.getPosition().x;
mPreviousY = mBowl.getPosition().y;
}
问题出在哪里?抱歉我的英语不好,提前谢谢... :)