libgdx物理系统的改进

libgdx物理系统的改进,libgdx,system,physics,frame-rate,Libgdx,System,Physics,Frame Rate,想用ashley ECS框架在libgdx中编写自己的物理。 所以我创建了一个物理系统,但它的性能在renderind中并不好。我认为它应该是独立于框架的,并添加以下代码,但我也不喜欢这种情况下的行为。这是代码 public class PhysicsSystem extends IteratingSystem { private float accumulator = 0; private static final float TIME_STEP = 1 / 120f;

想用ashley ECS框架在libgdx中编写自己的物理。 所以我创建了一个物理系统,但它的性能在renderind中并不好。我认为它应该是独立于框架的,并添加以下代码,但我也不喜欢这种情况下的行为。这是代码

public class PhysicsSystem extends IteratingSystem {
    private float accumulator = 0;
    private static final float TIME_STEP = 1 / 120f;


    private ComponentMapper<PhysicsComponent> pcm = ComponentMapper.getFor(PhysicsComponent.class);

    public PhysicsSystem(Family family) {
        super(family);
    }

    @Override
    public void update(float deltaTime) {

        float frameTime = Math.min(deltaTime, 0.25f);
        accumulator += frameTime;

        while (accumulator >= TIME_STEP) {
            accumulator -= TIME_STEP;
            super.update(TIME_STEP);
        }
    }

    @Override
    protected void processEntity(Entity entity, float deltaTime) {
        PhysicsComponent physicsComponent = pcm.get(entity);

        physicsComponent.applyForce(0, -9.8f * deltaTime);

        physicsComponent.position.add(physicsComponent.velocity.x * deltaTime, 
physicsComponent.velocity.y * deltaTime);

     }
}
公共类PhysicSystem扩展了迭代系统{
专用浮动累加器=0;
专用静态最终浮动时间_步=1/120f;
私有ComponentMapper pcm=ComponentMapper.getFor(physicComponent.class);
公共物理系统(家庭){
超级(家庭);
}
@凌驾
公共无效更新(浮动增量时间){
浮点帧时间=数学最小值(deltaTime,0.25f);
累加器+=帧时间;
while(累加器>=时间步长){
累加器-=时间步长;
super.update(时间步长);
}
}
@凌驾
受保护的void processEntity(实体、浮点deltaTime){
PhysicComponent PhysicComponent=pcm.get(实体);
物理成分。applyForce(0,-9.8f*deltaTime);
PhysicComponent.position.add(PhysicComponent.velocity.x*deltaTime,
物理成分。速度。y*deltaTime);
}
}

那么有什么方法可以提高我的物理水平呢?任何提示都有帮助。

你的问题是什么?将编辑帖子供你查看)thx你的问题是什么?将编辑帖子供你查看)thx