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

Author Topic: Best practice, for using delta time with objects ?  (Read 1217 times)

0 Members and 1 Guest are viewing this topic.

Drex

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Best practice, for using delta time with objects ?
« 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.

« Last Edit: June 21, 2023, 04:35:12 pm by Drex »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Best practice, for using delta time with objects ?
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Drex

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Best practice, for using delta time with objects ?
« Reply #2 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.

 

anything