3
\$\begingroup\$

I'm working on one of my first games and I've read that linking your game logic to FPS is bad because it will run differently at different FPS (obviously). I have already made some of the basic game dependent on frame rate and now that I know this, I would like to unlink the logic and render. I've learned that LibGdx has deltaTime in its render method for this, however I believe I'm misunderstanding how I am to use it.

For example, my movement currently looks something like this:

if (rightKeyisPressed)
    setVelocityX(movementSpeeD)
playerPos.add(getVelocity)

In my case, I would like the player to move 6 units per second. Since I built this on 60 fps, that means that movementSpeed is 0.1. Now the way I have seen deltaTime used is by scaling the movementSpeed based on the time like this:

setVelocityX(movementSpeed * deltaTime)

However, now I move very slow because delteTime is a very small number. How can I make movement still the same speed without depending on the fps? Sorry if I'm missing something obvious, I just can't seem to wrap my head around this.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

This is because movementSpeed should be how many units you would like your character to move per second (so your movement speed should be 6, for 6 units per second), and multiplying that by deltaTime in LibGDX will give you a value that will achieve the movement of movementSpeed per second. Delta times work differently depending upon how they are implemented, and in LibGDX this is how the default way is done, I hope this all made sense - I can elaborate more if needed, I hope I understood your question.

\$\endgroup\$
1
  • \$\begingroup\$ Thank you, I didn't realize that I need to change thing to a per second measurement. \$\endgroup\$
    – Panda
    Commented Jul 23, 2015 at 0:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .