2
我正在開發一個libgdx和box2d的Android遊戲。 我的問題是box2d中的物體插值效果不好......身體有點臃腫。如果沒有內插,身體就會「不起眼」。 以下是我的部分代碼:libgdx 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;
}
問題在哪裏? 對不起,我英語不好,並提前感謝... :)
爲什麼'如果(mAccumulator> 1F)'塊? – 2015-02-17 14:54:28