嗨,我正在LibGDX的帮助下开发一个游戏,并在游戏中使用Box2d。问题是,当在hdpi或平板电脑上运行我的游戏时,它运行得很好,但是对于、ldpi、和mdpi,box2d主体并没有采取相应的行动。
我认为,在这些手机上渲染需要更多的时间。那么,我如何为ldpi和mdpi phones.The值优化我在world.step isworldbox.step(Gdx.graphics.getDeltaTime(), 10, 2000);中传递的游戏。
谢谢。
发布于 2013-02-16 02:44:02
用帧速率作为时间步长是个坏主意。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);
}https://stackoverflow.com/questions/14870273
复制相似问题