One of the important things to keep on mind while designing a game is that the game, once released, will be played on different machines, with different video cards, processors and architectures. And if you don’t take this into account while designing all your game, you can find the game does not behave correctly on all machines.

One of the most important aspects of this is the game speed. A well written game will be as playable on a computer that shows 15 fps and in a computer that shows 150 fps, and that’s exactly where delta timing can be very useful.

So, what is exactly delta-timing?

Delta timing is a technique to make the ‘logical’ speed of a game independent from the fps. This technique is based on the Delta Factor. The delta factor is a -usually- double precision numeric value that counts the time elapsed between frames and acts like a scaling factor, so if you multiply any displacement or movement in the game by this factor, you can be sure the movement behaves properly on most computers, regardless of the FPS.

So, in order to move a object on the screen by 10 units per game loop, instead of doing this:

if KeyDown(Key_right) Then MyObject.X = MyObject.X + 10

If working with Delta time, you would do this:

if KeyDown(Key_right) Then MyObject.X = MyObject.X + 10 * DeltaFactor

Providing a reliable way to get a working delta factor, can be a bit complicated, that’s why I wrote this module.

This module exposes a shared class (no instances required) called Delta. Those methods are:

Delta.Factor() -> This returns the Delta time factor
Delta.FlushTiming -> This resets the delta time calculation. Useful after a period of pause (loading media etc.)
Delta.GetFPS() -> Returns the current FPS
Delta.GetMaximumTimeFactor() -> Returns the maximum value allowed for the Factor (to avoid the factor being too big on too slow machines)
Delta.GetMinimumTimeFactor() -> Returns the minimum value allowed for the factor (to avoid the factor being too small on too fast computers) delay time will be added if needed to preserve logic speed.
Delta.IsComputerSlow() -> Returns TRUE if the computer is too slow and we're getting the maximum time factor.
Delta.IsPaused() ->  Returns TRUE if the delta timing calculation has been paused
Delta.PauseDeltaTiming() -> Pauses the Delta timing calculation
Delta.ResumeDeltaTiming() -> Resumes the Delta timing calculation if it has been paused
Delta.SetMaximumTimeFactor(Factor:Double) -> Self explanatory
Delta.SetMinimumTimeFactor(value:double)  -> Self explanatory

Usually, on a game, we only need to use Delta.Factor(). This module is designed in a way that no single line of code is needed by the importing program. Delta.Factor is calculated automatically, from the first Flip internally using a flip hook, so not even an update delta time is required. Can’t be easier!

Leave a Reply