【发布时间】:2015-10-19 16:12:04
【问题描述】:
嘿,我的问题是,在 PhysicsHandler 的 onUpdate 中,pSecondsElapsed 经常从 0.016... 跳到 0.038,这使得玩家移动得如此之大,以至于看起来玩家会滞后。 这里是来自 onUpdate 的重要代码:
@Override
protected void onUpdate(final float pSecondsElapsed, final IEntity pEntity) {
if(this.mEnabled) {
/* Apply linear acceleration. */
final float accelerationX = this.mAccelerationX;
final float accelerationY = this.mAccelerationY;
if(accelerationX != 0 || accelerationY != 0) {
this.mVelocityX += accelerationX * pSecondsElapsed;
this.mVelocityY += accelerationY * pSecondsElapsed;
}
/* Apply angular velocity. */
final float angularVelocity = this.mAngularVelocity;
if(angularVelocity != 0) {
pEntity.setRotation(pEntity.getRotation() + angularVelocity * pSecondsElapsed);
}
/* Apply linear velocity. */
final float velocityX = this.mVelocityX;
final float velocityY = this.mVelocityY;
if(velocityX != 0 || velocityY != 0) {
pEntity.setPosition(pEntity.getX() + velocityX * pSecondsElapsed, pEntity.getY() + velocityY * pSecondsElapsed);
}
}
}
顺便说一句,我只使用线速度。有人对此有解决方案吗?感谢您的帮助!
【问题讨论】:
-
你不能忽略 pSecondsElapsed 并乘以某个常数吗?
-
@m.antkowicz 如果我这样做,游戏速度将取决于 fps