Andengine PhysicsHandler使玩家显得迟钝 [英] Andengine PhysicsHandler makes player look laggy

查看:79
本文介绍了Andengine PhysicsHandler使玩家显得迟钝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我的问题是,在PhysicsHandler的onUpdate中,pSecondsElapsed通常从0.016 ...跃升至0.038,这使得玩家的步伐如此之大,以至于玩家看起来会滞后. 这里是onUpdate的重要代码:

Hey my problem is that in the onUpdate in PhysicsHandler the pSecondsElapsed often jumps from 0.016... to 0.038 which makes the player move in such big steps that it looks like the player would lagg. Here to the importante Code from the 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);
        }
    }
}

顺便说一句,我只使用线速度.有人对此有解决方案吗?感谢您的帮助!

btw I am only using the linear velocity. Does anyone have a solution for this? Thanks for your help!

推荐答案

我继续浏览了该引擎的存储库,发现一个可能对您有帮助的类.基本引擎类具有名为

I went ahead and looked through the repository for this engine and I found a class that may be a help to you. The base engine class has an extension called Fixed Step Engine that should allow you to control the delta time per frame, which may be worth trying out (if you haven't already) for smoother physics.

这篇关于Andengine PhysicsHandler使玩家显得迟钝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆