Delay(17) is NOT the way to go, since the game will wait the same amount after every frame. On one machine, calculations will take 3ms + 17ms delay = 20ms per frame = 50FPS, but a slower machine will take 8ms + 17ms delay = 25ms per frame = 40FPS, and the game will slow down. To have a steady FPS, what you need to do is:
Code:
Function GetMSecs():Comp;
begin Exit(TimeStampToMSecs(DateTimeToTimeStamp(Now()))) end;
This function uses standard functions from SysUtils and returns current time as 64bit int containing the amount of miliseconds since 30.12.1899.
In the game loop:
Code:
Time := getMSecs();
(* Do all the calculations, drawing, et cetera *)
While (getMSecs() - Time < DELAY_BETWEEN_FRAMES) do Delay(1)
This way, unless the machine REALLY slows down, to the point that calculating/rendering a frame takes longer than DELAY_BETWEEN_FRAMES, you're going to have a steady FPS.
Edit:
Oh, and also, SysUtils contains Sleep(), which does the same crt.Delay() does.
Bookmarks