Shawn S.
Shawn S.

Reputation: 97

Incorrect delta time caused by window movement

I'm creating a Minecraft clone menu, the yellow text on the logo is causing problems. It is a sprite and I'm using the scale methods to scale it up and down like in the actually menu of the game. This scaling uses Delta Time so it is runs smoothly. But whenever I seem to move the window it pauses my game momentarilly and creates an inaccurate Delta Time such as: 3.0482762 9.7077E-4 4.25514E-4 . These inaccuraces make my text scale more than I want, here is my code I am using LibGdx:

@Override
public void render(float delta) {
    // Update
    System.out.println(delta);

    if(titleEnlargement)
    {
        if(title.getScaleX() < 1.1)
            title.setScale(title.getScaleX() + (delta * 0.4f));
        else
            titleEnlargement = false;
    }
    else if(!titleEnlargement)
    {
        title.setScale(title.getScaleX() - (delta * 0.4f));
        if(title.getScaleX() <= 1)
            titleEnlargement = true;
    }

    // Render
    batch.draw(background, 0, 0);
    logo.draw(batch);
    title.draw(batch);
}

Upvotes: 0

Views: 61

Answers (1)

user4514478
user4514478

Reputation:

You can clip the delta so that it never exceeds a certain value. This is what Stage does to prevent jitters with actions.

Place the following at the start of your render method:

delta = Math.min(delta, 1 / 30f);

Upvotes: 1

Related Questions