LIBGDX 中的 Delta 时间是多少 [英] What is a Delta time in LIBGDX

查看:28
本文介绍了LIBGDX 中的 Delta 时间是多少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LIBGDX 中的 Delta 时间是多少?我读了很多关于那个的帖子.据我所知,Delta 时间是,

What is a Delta time in LIBGDX? I read many posts regarding that. To my knowledge, Delta time is,

  • 上一帧和当前帧之间的时间间隔
  • 增量时间将加到 1,因为它每秒计算 x 帧,即(帧的 1/x)
  • 为了让游戏的速度恒定,我们使用 dt

  • The time gap between previous and current frame
  • delta time will add upto 1 since its the computation of x frames per second ie.(1/x of the frames)
  • To make the speed constant for the game we use dt

如果我们说 60 *dt 那么它将每秒移动 60 帧,无论移动设备的速度如何(例如).

If we say 60 *dt then it will move 60 frames per second, no matter what the speed of the mobile(for instance) is.

所以,这就是我对 delta 时间的了解,但我并没有清楚地了解它,因为无论是对于更新还是渲染方法,我们都在传递 delta 时间,但是我们指定在代码中的哪个位置计算每秒?

So, this is what I know about delta time but I am not getting a clear view about it because , be it for an update or render method we are passing the delta time but where in the code we are specifying to calculate for PER SECOND?

例如,

    public void update(float dt)
     {
       float distance +=2*dt;
     }

这段代码每秒会移动 2 帧吗?如果是这样,那么下面的代码会做什么?

will this code move 2 frames per second? If so then what the below code will do?

    public void update(float dt)
    {
      ....
    }
    public void render(float delta)
    {
      update(delta);
    }

所以,我需要答案,

  • 上面的代码是什么意思??
  • 代码背后究竟发生了什么?
  • 我们为什么要这样做?
  • 我们在这段代码的什么地方指定它必须像上面的例子一样每秒移动 x 帧?

  • what the above code is implying??
  • What's actually happening behind the code?
  • Why are we doing so?
  • where in this code we are specifying it must move x frames per second like the previous above example?

我可以理解渲染方法正在将增量时间传递给更新方法,但我需要对此有一些清晰的认识.对不起,如果这个问题看起来很愚蠢,但是如果不知道发生了什么就很难继续.任何帮助都会很棒!

I can understand the render method is passing the delta time to the update method but I need some clear view about it. Sorry if the question seems stupid but it's really hard to proceed without actually knowing what's happening .Any help would be great !!

推荐答案

Gdx.graphics.getDeltaTime() 是上一次调用开始到当前调用开始之间的时间 render().这也是您在 Screen 中获得的价值#render() 方法.而已.没有黑魔法什么的.它只需要当前时间并从中减去以前的时间.该值的单位是秒.请注意,它加起来不等于一.

Gdx.graphics.getDeltaTime() is the time between the start of the previous and the start of the current call to render(). It is also the value you get in your Screen#render() method. That's it. No black magic or something. It just takes the current time and subtracts the previous time from it. The unit of this value is seconds. Note that it does not add up to one.

因此,如果上一次调用该方法的时间是在 6:51:30.0159512 pm 并且当前调用它的时间是在 6:51:30.0324858 pm 那么区别是 0.0165346 秒.

So if the previous time the method was called was at 6:51:30.0159512 pm and the current time it is called is at 6:51:30.0324858 pm then the difference is 0.0165346 seconds.

速度(速度)以单位"每秒测量,例如 meter per second 或简称:m/s.如果您的汽车以 360 m/s 行驶,经过的时间是 0.0165346 s,那么您在这段时间内行驶的距离是 0.0165346*360 s*m/s => 5.952456 m,差不多6米.

Speed (velocity) is measured in "units" per second, for example meter per second or short: m/s. If your car travels at 360 m/s and the time elapsed is 0.0165346 s, then the distance you've traveled in that time is 0.0165346*360 s*m/s => 5.952456 m, so almost 6 meters.

请注意,这是基本的物理特性,并非特定于 libGDX.如果您觉得难以理解,那么您可能需要阅读 velocity.

Note that this is basic physics, it is not specific to libGDX. If you find it hard to understand then you might want to read up on velocity.

回答你的基本问题,我猜是关于将你的渲染方法拆分为一个单独的更新方法.

To answer your bottom questions, which I guess are about splitting your render method into an separate update method.

  • 代码没有任何暗示
  • 代码背后没有任何东西
  • 使用定义明确的短方法通常是一种很好的做法,请阅读:关注点分离
  • 不知道帧"是什么意思,但速度乘以时间获取距离

这篇关于LIBGDX 中的 Delta 时间是多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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