简体   繁体   English

如何在Slick2D / LWJGL或一般的游戏编程中使用“增量”?

[英]How do I work with “delta” in Slick2D/LWJGL or game programming in general?

All I know is that delta relates somehow to adapting to different frame rates, but I'm not sure exactly what it stands for and how to use it in the math that calculates speeds and what not. 我所知道的是,增量在某种程度上与适应不同的帧速率有关,但是我不确定它到底代表什么,以及如何在计算速度的数学运算中使用它,而不能确定。 Where is delta declared? 增量在哪里声明? initialized? 初始化了吗? How is it used? 如何使用? How are its values (min,max) set? 如何设置其值(最小,最大)?

It's the number of milliseconds between frames. 这是帧之间的毫秒数。 Rather than trying to build your game on a fixed number of milliseconds between frames, you want to alter your game to move/update/adjust each element/sprite/AI based on how much time has passed since the last time the update method has come around. 与其尝试在帧之间的固定毫秒数上构建游戏,不如要根据自上次更新方法以来已过去的时间来更改/移动/更新/调整每个元素/精灵/ AI,从而更改游戏周围。 This is the case with pretty much all game engines, and allows you to avoid needing to change your game logic based on the power of the hardware on which you're running. 几乎所有游戏引擎都是这种情况,并且可以避免基于运行硬件的功能来更改游戏逻辑。

Slick also has mechanisms for setting the minimum update times, so you have a way to guarantee that the delta won't be smaller than a certain amount. Slick还具有用于设置最短更新时间的机制,因此您有一种方法可以保证增量不会小于一定量。 This allows your game to basically say, "Don't update more often than every 'x' milliseconds," because if you're running on powerful hardware, and have a very tight game loop, it's theoretically possible to get sub-millisecond deltas which starts to produce strange side effects, such as slow movement, or collision detection that doesn't seem to work the way you expect. 这样一来,您的游戏基本上就可以说:“更新的频率不要超过每隔'x'毫秒”,因为如果您在功能强大的硬件上运行,并且游戏循环非常紧密,则理论上可以获得毫秒级的增量会开始产生奇怪的副作用,例如动作缓慢或碰撞检测,这些似乎无法按您预期的方式工作。

Setting a minimum update time also allows you to minimize recalculating unnecessarily, when only a very, very small amount of time has passed. 设置最短更新时间还可以使您仅在经过非常少的时间后就将不必要的重新计算减到最少。

Have a read of the LWJGL timing tutorial found here . 阅读此处的LWJGL时序教程。 Its not strictly slick but will explain what the delta value is and how to use it. 它并不严格,但会解释什么是delta值以及如何使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM