Search code examples
javalibgdx

Why is the delta so tiny?


I am currently trying to create a scrolling camera and have successfully done so, however I found that the value of delta is very small and was wondering why this was the case.

Shooter: 0.016785555
Shooter: 0.016596204
Shooter: 0.016559256
Shooter: 0.017374134
Shooter: 0.015813652
Shooter: 0.016723463
Shooter: 0.016657267
Shooter: 0.0167522

Should I bump them up? Or am I missing something entirely?


Solution

  • This delta, aka as deltaTime, is the time your last frame took to render.

    Let's assume that your app has 60 frames per second (FPS), then your deltaTime should roughly be 0.01666... which is your case as well.

    Usually you will use it like this:

    float speed = 10f;
    float positionX = positionX + (speed * deltaTime);
    

    If this is part of your render routine, which runs in every frame, your positionX will increase by 10 every second. Without deltaTime your speed will totally depend on the speed of your device.