2

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;
}

問題はどこだ?私の悪い英語で申し訳ありませんが、事前に感謝します... :)

4

1 に答える 1