Speed in game with libgdx
libgdx
Solution
Use `delta`.
`Gdx.graphics.getDeltaTime()` method return secods since last render frame. Usually this value is very small, and it equal 1 / FPS.
@Override
public void render()
{
// limit it with 1/60 sec
float dt = Math.min(Gdx.graphics.getDeltaTime(), 1 / 60f);
// then move your characted according to dt
player.pos = player.pos + player.speed * dt;
// or, you could mute the speed like this:
player.pos = player.pos + player.speed * dt * 0.85;
}
Problem
I'm making a game using libgdx. For now, every character has a speed, corresponding actually to the number of render the game wait before update the character. For example, if the character has a speed of 15, it will be updated every 15 renders. I'm conscious that this is not how it has to be done. What is the proper way to do this? I really want to make a speed in %, for example a character will have a speed of 85%.