Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Understanding delta time  (Read 1760 times)

0 Members and 1 Guest are viewing this topic.

AdrianHEY

  • Newbie
  • *
  • Posts: 14
    • View Profile
Understanding delta time
« on: April 16, 2021, 09:33:52 am »
I am trying to make a function that return the delta time value but I have no idea how to do that. Can someone explain how can I calculate the delta time every frame?
Here is what I did so far but I don't think its right.
 float deltaTime() {
    sf::Clock deltaClock;
        sf::Time dt = deltaClock.restart();
        std::cout << dt.asSeconds() << std::endl;
        return dt.asSeconds();
}

helping and being helped

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Understanding delta time
« Reply #1 on: August 27, 2022, 02:16:21 pm »
Hello, i don't know what happened with your code, I started programming in SFML a day ago XD, but i think you could do this:

in the main function you declarate the dt and the clock, you should add a multiplier too.

then in the main loop:

dt = clock.restart().asSeconds();

if you want movement you should do something like this

if (sf::Keyboard::isKeyPressed(sf::Keyboard::'Key'){
    vector2_variable.axis = 1 * dt * dtMultiplier;
}

shape_or_sprite.move(vector2_variable);

and that's all i didnt test it but if it fail surely be a nuisance

 

anything