Posted:
Sep 22, 2007 @ 12:58am
by Dan East
I almost use milliseconds (1/1024th of a second to be exact).
So if velocity is in units per second, and delta time is an integer representing (almost) milliseconds duration of the frame:
pos += (velocity * delta_time) >> 10;
Now I don't care about the .024 loss of precision per second, so I use actual milliseconds (1/1000th) for delta_time (GetTickCount()). If that is a problem for you (maybe due to video / audio timing or something that must be properly synchronized) then you can adjust delta_time just once each frame to represent 1/1024 of a second.
Also, each frame you need to check to see if delta_time is zero. If your game runs really fast, or is on fast hardware, you can have issues with that. If delta_time is zero I just sleep for a couple milliseconds and start the frame over. That will make a massive difference with battery life if your game is not using 100% of the CPU.
Dan East
Posted:
Sep 22, 2007 @ 1:46am
by Cardinal
Hmm that seems to make more sense than the way I was doing it!
I'm going to have to experiment some more!