0

こんにちは、私は LibGDX の助けを借りて、Box2d を使用してゲームを開発します。問題は、hdpi またはタブレットでゲームを実行すると問題なく動作することですが、ldpiおよびmdpiの場合、box2d 本体が適切に動作しないことです。

これらの携帯電話でのレンダリングには、はるかに多くの時間がかかっていると思います。では、ゲームを ldpi および mdpi 電話用に最適化するにはどうすればよいでしょうか。world.step で渡す値は次のとおりです。worldbox.step(Gdx.graphics.getDeltaTime(), 10, 2000);

ありがとう。

4

1 に答える 1

0

フレーム レートをタイム ステップとして使用することはお勧めできません。Box2D のマニュアルには次のように書かれています。

可変タイム ステップでは可変結果が生成されるため、デバッグが困難になります。そのため、タイム ステップをフレーム レートに結び付けないでください (本当にそうしなければならない場合を除きます)。

また、速度と位置の反復に使用する値が大きすぎます。Box2D のマニュアルには次のように書かれています。

Box2D の推奨反復回数は、速度が 8 回、位置が 3 回です。

次のように、固定時間ステップと推奨される反復回数を試してください。

float mAccomulated = 0;
float mTimeStep = 1.0f / 60.0f;
int mVelocityIterations = 8;
int mPositionIterations = 3;

void updatePhysicWorld()
{
    float elapsed = Gdx.graphics.getDeltaTime();

    // take into account remainder from previous step
    elapsed += mAccomulated;

    // prevent growing up of 'elapsed' on slow system
    if (elapsed > 0.1) elapsed = 0.1;
    float acc = 0;

    // use all awailable time
    for (acc = mTimeStep; acc < elapsed; acc += mTimeStep)
    {
        mWorld->Step(mTimeStep, mVelocityIterations, mPositionIterations);
        mWorld->ClearForces();
    }

    // remember not used time
    mAccomulated = elapsed - (acc - mTimeStep);
}
于 2013-02-16T02:44:02.657 に答える