渲染方法 libgdx 中的增量值 [英] Delta value in render method libgdx

查看:14
本文介绍了渲染方法 libgdx 中的增量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Screen 类的 render 方法中检查了 delta 值.我看到它不是恒定的.任何人都可以说出它来自哪里以及它是什么吗?不同的屏幕尺寸有区别吗?如果是这样,我们该如何克服呢?我问这个是因为我的玩家跳跃取决于增量时间,有时它跳得太高.....

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;
}

...那么位置在快速设备上的变化会更快,而在慢速设备上的变化速度会变慢,这只是因为渲染方法被调用的次数不同.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆