OmegaThreadTimer provides high-precision timing for your games. It has the following features:
Enabled: Boolean When enabled the timer will start calling
it's OnTimer() event at the specified interval.
Priority: TThreadPriority The timer-thread's priority, defaults
to tpNormal, probably doesn't have to be changed anyway.
TargetFPS: Integer The number of frames per second you want
to 'emulate'. This means that the OnTimer() event will be called this number
of times. Defaults to '0', which means OnTimer() will be called as many times
as possible.
Delta: Double Can be read in the OnTimer event handler. If
TargetFPS > 0 this represents the number of target frames that have
passed since the last call (it is always possible a computer is too slow, in
which case this value van be >1!). If TargetFPS = 0 this represents the number
of seconds that have passed since the last call.
FPS: Integer The current frames-per-second. This actually means
the number of times the OnTimer event handler has been called, ofcourse. The
FPS is not weighted or anything since this is just for indication of the FPS
and should not take too much CPU time to process this way.
OnTimer: TNotifyEvent This event handler is called by the timer when the specified amount of time according to TargetFPS is reached.
Using TargetFPS > 0: Your OnTimer event handler could look like this to have a sprite move 2 pixels per frame, regardless of the actually called frames per second, where ThreadTimer is the instance of TOmegaThreadTimer calling this event handler:
MySprite.x := MySprite.x + ThreadTimer.Delta * 2;
Using TargetFPS = 0: Your OnTimer event handler could look like this to have a sprite move 30 pixels per second, regardless of the actually called frames per second, here ThreadTimer is the instance of TOmegaThreadTimer calling this event handler:
MySprite.x := MySprite.x + ThreadTimer.Delta * 30;