libgdx - libgdx 物理系统改进
问题描述
想用 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);
}
}
那么有什么技术可以提高我的物理性能吗?任何提示都可以提供帮助。
解决方案
推荐阅读
- javascript - Google Map Javascript API 我想隐藏除银行以外的所有内容
- python - 如何让乌龟跟随 Python 中的鼠标光标?
- android - 当通过导航组件的深层链接打开片段而不是返回到开始目标片段时,在返回按钮上关闭应用程序
- django - Django在打开记录后设置布尔值
- python - 使用 pyqt 将绘图添加到 GraphicsLayoutWidget
- swift - 公共函数 addObserver
(主题:T.Type,观察者:M:T){} - elasticsearch - s3到elasticsearch摄取问题
- javascript - 如何在Javascript中重新排列嵌套的promise
- r - 合并两个表对象以便在 r 中创建一个新的数据框
- firmware - 如何使用串行模式闪烁 variscite dart imx6ul evk 板