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

本秂侑毒 提交于 2019-12-20 04:30:10

问题


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?


回答1:


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. 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. 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.

Setting a minimum update time also allows you to minimize recalculating unnecessarily, when only a very, very small amount of time has passed.




回答2:


Have a read of the LWJGL timing tutorial found here. Its not strictly slick but will explain what the delta value is and how to use it.



来源:https://stackoverflow.com/questions/8282501/how-do-i-work-with-delta-in-slick2d-lwjgl-or-game-programming-in-general

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!