嘿,我的問題是,在PhysicsHandler的onUpdate中,pSecondsElapsed經常從0.016 ...跳到0.038,這使得玩家在如此大的步驟中移動,看起來像玩家會落後。 這裏從的onUpdate的重要提示代碼:Andengine PhysicsHandler讓玩家看起來遲緩
@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);
}
}
}
BTW我只使用線速度。有沒有人有這個解決方案?謝謝你的幫助!
你不能忽略* pSecondsElapsed *並把它乘以一些常量嗎? –
@ m.antkowicz如果我會這樣做遊戲速度取決於fps – Hansfritzi