Code archives/Miscellaneous/LimitFrameRate
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This code will dynamically delay the execution of your program to limit the framerate. It is accurate within 1 FPS. All you have to do, is adding one single function call at the top of your main loop: LimitFrameRate() That's all. Don't forget to place the global variables at the very top of your program. The default framerate is set to 50. You can modify it this way: LimitFrameRate(xxx) Where xxx is the required framerate. | |||||
Global FrameTime Global Period Function LimitFrameRate(FPS = 50) If FrameTime = 0 Then Period = 1000 / FPS FrameTime = MilliSecs() EndIf ; Make sure the framerate isn't above the specified setting While (FrameTime + Period) > MilliSecs() Delay 1 Wend FrameTime = MilliSecs() End Function |
Comments
| ||
how about: FrameTime = CreateTimer(60) ;mainloop while keyhit(1)=0 WaitTimer(FrameTime) wend shorter and simpler. In the end both are bad, as they block the whole mainloop Using timebased movement is far better |
Code Archives Forum