jemystack
jemystack

Reputation: 420

2d games - It is safe to leave dealing with delta time on animation games especially with libgdx engine

i'm new to games development

in 2d games i'm using a final delta time for all frames and for measuring speed and so on;

i want to know if there is a problem can happen when i use final delta time instead of use counted-by-engine delta time

and also where to use the final delta and where to use the counted one

like game in game.java

class game extends com.badlogic.gdx.Game {

    final float delta = 1 / 60F;

    @Override
    public void create() {
    }


    @Override
    public void render() {
        if (screen != null) screen.render(delta);
        /////////// do stuff Depended on final delta
        player.translate(150, delta)
    }
}

thanks :)

Upvotes: 1

Views: 209

Answers (2)

DHa
DHa

Reputation: 669

In LibGDX the default frame rate is 60.

As long as the device running the application can keep up with that, a final delta of 1 / 60 will appear correct because that will be about equal to the Gdx.Graphics.getDeltaTime(). If however you either change the frame rate or the device cannot keep up with a frame rate of 60 you will get weird behavior.

Lets say it can only run at 30 frames per second, then your movement will only by 30/60 of your intended distance. So your application will slow down to half speed. Unless that was your intention, it will be a problem.

Using Gdx.Graphics.getDeltaTime() as suggested by @Ezra is usually the way to go if you want the intended movement even on a slower device.

Upvotes: 0

Ezra
Ezra

Reputation: 66

Why not just use Gdx.Graphics.getDeltaTime()? The value is approximately 60, but I often see it ranging from 59 to 61.

Meant this as a comment, sorry.

Upvotes: 2

Related Questions