渲染方法libgdx中的增量值 [英] Delta value in render method libgdx
问题描述
我在Screen类的render方法中检查了增量值.任何人都可以分辨出它的来源和来源吗?它在不同的屏幕尺寸上是否有所不同?如果是这样,我们该如何克服呢?我问这是因为我的球员跳高取决于三角时间,有时跳得太高.....
I have check delta value in render method in Screen class.. I saw it is not constant. Can any body tell where it come from and what it is? And does it differ in different screen sizes? If it is so how can we overcome this? I am asking this cause my player jump depends upon delta time and sometimes it jumps too high .....
推荐答案
deltaTime
与屏幕尺寸无关.这是渲染最后一帧所花费的时间.如果是LibGDX,则呈现的内容还包括您在render()
方法中执行的所有逻辑.
The deltaTime
has nothing to do with screen sizes. It is the amount of time the last frame took to be rendered. Rendered in case of LibGDX also includes all the logic you execute in your render()
method.
通常,您希望游戏在不同设备上以相同的速度运行.如果您的渲染方法看起来像这样...
Usually you want a game to run at the same speed on different devices. If your render method looks something like this...
public void render(float deltaTime) {
float speed = 5f;
position = position + speed;
}
...然后,位置会在快速设备上变化更快,而在慢速设备上变化不快,只是因为render方法的调用时间不同.
...then the position would change faster on fast devices and less fast on slow devices, just because the render method is called a different amount of times.
为解决此问题,有一个deltaTime
,以LibGDX为单位,以秒为单位.为了让位置在不同设备上以相同的速率变化,通常需要这样做:
To overcome this issue, there is the deltaTime
which in case of LibGDX is in seconds. To let the position change at the same rate on different devices, you usually do it like this:
public void render(float deltaTime) {
float speedPerSecond = 5f;
position = position + (speedPerSecond * deltaTime);
}
这篇关于渲染方法libgdx中的增量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!