I was trying to calculate elapsed time in libgdx by adding in the render method the value of delta to my float value which is the time i measure since play state starts. The bug or problem, how you want to call it, is that by my calculations, the time displayed doing this is two times the real time. I tried to divide by 2 and I was pretty close to the real time, which means that by adding delta every render call I don't get real time in seconds. Why is this happening?
private float time=0;
public void render () {
time +=Gdx.graphics.getDeltaTime();
}
the above doesn't get the real time and my question is why? EDIT: i am using a screen but it doesn't matter i tried both Gdx.graphics.getDeltaTime() and delta argument from render method.
You can use wrapper TimeUtils.
Get current time:
long startTime = TimeUtils.millis();
Get time elapsed since startTime:
long elapsedTime = TimeUtils.timeSinceMillis(startTime);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With