SFML community forums

Help => General => Topic started by: Drex on June 21, 2023, 03:27:04 pm

Title: Best practice, for using delta time with objects ?
Post by: Drex on June 21, 2023, 03:27:04 pm
Hello guys,

Just a quick question.....

Is it better to have, one clock object, in say, the game class, and pass that to all other objects ?

or, should every object, have its own clock for delta time ?

I think, the clock per object approach, would be more accurate.....

Thanks.

Title: Re: Best practice, for using delta time with objects ?
Post by: eXpl0it3r on June 21, 2023, 07:46:19 pm
Depends a bit on the usage of the clock.

If you want a delta time, then it's better to have one clock, get the delta time from that clock once and then pass that delta time around, otherwise you might get different timings.

If you want to measure multiple things at once, you could have a start/stop sf::Time to get the difference from a running clock, or you can have a dedicated clock for that measurement. Both work and best to pick, what is easier for your code base.
Title: Re: Best practice, for using delta time with objects ?
Post by: Drex on June 21, 2023, 08:35:02 pm
Ok, thanks for clearing that up.

I just wanted to, implement a basic delta time for my objects, and wasn't sure which way to go about it.

Thanks.