Delta value in render method libgdx

后端 未结 2 1911
无人共我
无人共我 2021-01-12 11:27

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 sc

2条回答
  •  粉色の甜心
    2021-01-12 12:16

    The float delta in your render(delta) method is the time between the last frame and this frame, given in seconds. You can get this value everywhere, by calling Gdx.graphics.getDelta(). This value is smoothed over n frames. To get the real time (which is not really neccesary in most cases) you can call Gdx.graphics.getRawDeltaTime(). This value is used to have move the objects in the game, depending on the elapsed time between the frames, instead of moving them at a fixed amount of pixels. To do this you can simply mulitply your movementSpeed with this delta to get the distance your object should travel.

    I would suggest to limit your delta time, as huge delta times (caused by slow devices or something else going on) can mess up for example collision detection. To limit it to, for example, the delta time of 30FPS you can simply say delta = Math.min(delta, 1/30);

提交回复
热议问题