There are different ways to achieve the goal of framerate independent movement.

The simplest and for a lot of cases sufficient approach for me is multiplying the delta-time with your movement calculation (your second approach).

In order to figure out the right units, you go back physics calculations:

`s = v * dt`And then replace the meter units with pixels or similar and you get

`[px] = [px/s] * `So something like this should do:

auto frame_time = clock.restart();

// ...

entity.move(velocity * frame_time.asSeconds());

Personally, I also recommend to use a normalized direction vector, that way you get the diagonal movement speed correct and can basically pick whatever direction you want.

entity.move(normalize(direction_vector) * velocity * frame_time.asSeconds());

Also once write a normalize function, not sure how efficent and precise it is, but it covers some edge cases.

sf::Vector2f normalize(sf::Vector2f vector)

{

constexpr auto units_in_last_place = 2;

auto norm = std::sqrt((vector.x * vector.x) + (vector.y * vector.y));

// Prevent division by zero

if (norm <= std::numeric_limits<float>::epsilon() * norm * units_in_last_place

|| norm < std::numeric_limits<float>::min())

{

return sf::Vector2f{};

}

return vector / norm;

}

Now for more advanced games and certain micro stutter prevention, you'd use a

fixed time step and do interpolation calculations.