Search code examples
javalibgdx

DeltaTime not updating properly?


I'm having trouble with my deltaTIme basically what I'm trying to do is add 1 every second to a variable.

private int num=0
private float deltaTime=Gdx.graphics.getDeltaTime();

public void render(){
    deltaTime=Gdx.graphics.getDeltaTime();// updating

    num += 1*deltaTime;
    System.out.println(num);
}

and the output is this

    0
    0.016612083 //it does not add 1 to num every second
    0
    0.016679354
    0
    0.016680228
    0
    0.016672073
    0

Solution

  • Using num++ is wrong because it would just add 1 to num every time you call the render-function. I cant see whats wrong in your code, so probably the delta time is not updated properly.