什么是LIBGDX中的Delta时间 [英] What is a Delta time in LIBGDX

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

问题描述

LIBGDX中的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.

所以,这是我对增量时间的了解,但是我对此并不清楚,因为对于更新或渲染方法,我们传递的是增量时间,但是在代码中我们指定要计算的时间每秒钟?

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?

我可以理解render方法正在将增量时间传递给update方法,但是我需要一些清晰的视图.很抱歉,如果问题看起来很愚蠢,但是如果不真正知道正在发生的事情,这真的很难进行.任何帮助都将是很棒的!

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

推荐答案

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

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.如果您难以理解,则可能需要阅读速度.

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.

  • 代码不暗示任何内容
  • 代码背后没有任何东西
  • 使用定义明确的简短方法通常是一种好习惯,请阅读:关注点分离
  • 不知道框架"是什么意思,但是速度乘以时间 得到距离
  • The code is not implying anything
  • There is nothing behind the code
  • Using well defined short methods is usually a good practice, read: separation of concerns
  • No clue what you mean by "frame" but the velocity is multiplied by the time to get the distance

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

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