I would not recommend using WaitTimer() to halt your program so that is fits a certain FPS. Instead Use Delta Time:
DeltaT#=(MilliSecs()-TimeD#)/1000: TimeD#=MilliSecs()
Now at every place where you apply something over time, Multiply it with DeltaT. Like Speed=Speed + Acceleration*DeltaT. Or X=X+Speed*DeltaT. In this way the game will flow the same for someone with a fps of 20 and someone with a fps of 900. If you use DeltaTime, The speed, for example, will be set as pixels/second. Let's say you want to travel the screen in 3secs. Set Speed=ScreenWidth()/3, or if you have a resolution of 800x600 Speed=800/3M;Pixels/sec. Also Whenever you want something to happen at a given time USE Millisecs() and RealTimers. So that you depend on real-life time and not a in game counter Like Time=Time+1...
For the sake of the loop (I know it's messy), it's not a function, here it is. But that is preference only. I like to have the MAIN-loop after all variables/Types and then there is no real need for a function.
And a Forum Tip: Write <CODE> to start CODEBLOCK <CODE/> to end it BUT use [ instead of < and ] instead of >
DeltaT#=(MilliSecs()-TimeD#)/1000: TimeD#=MilliSecs()
Now at every place where you apply something over time, Multiply it with DeltaT. Like Speed=Speed + Acceleration*DeltaT. Or X=X+Speed*DeltaT. In this way the game will flow the same for someone with a fps of 20 and someone with a fps of 900. If you use DeltaTime, The speed, for example, will be set as pixels/second. Let's say you want to travel the screen in 3secs. Set Speed=ScreenWidth()/3, or if you have a resolution of 800x600 Speed=800/3M;Pixels/sec. Also Whenever you want something to happen at a given time USE Millisecs() and RealTimers. So that you depend on real-life time and not a in game counter Like Time=Time+1...
For the sake of the loop (I know it's messy), it's not a function, here it is. But that is preference only. I like to have the MAIN-loop after all variables/Types and then there is no real need for a function.
And a Forum Tip: Write <CODE> to start CODEBLOCK <CODE/> to end it BUT use [ instead of < and ] instead of >
; - - - - M - A - I - N - - L - O - O - P - - - While Not KeyDown(1) Cls If KeyHit( SPACE ) TEST=TEST+1 :If TEST >= 8 TEST = 0 If KeyHit( BACKSPACE ) TEST=TEST-1 :If TEST <= 0 TEST = 7 If KeyHit( T ) If TEXTON=1 TEXTON=0 Else TEXTON=1 EndIf If KeyHit( F ) If FLIPFALSE=1 FLIPFALSE=0 Else FLIPFALSE=1 EndIf If KeyHit( R ) If RECORD=1 RECORD=0 Else RECORD=1 EndIf ;FPS_Counter < Runs and displays the FPS ;-------------------------------------------- FPS_Counter=FPS_Counter+1 If FPS_Counter_time+1000 =< MilliSecs() FPS=FPS_Counter;<- Frames/Sec FPS_Counter=0 FPS_Counter_time=MilliSecs() EndIf Text 10,80,"Current FPS: "+FPS ;-------------------------------------------- DeltaT#=(MilliSecs()-TimeD#)/1000;Delta Timer TimeD#=MilliSecs() If DeltaT < 1 ; __Update___________ UpdatePlayer() ; Sends data BP_UpdateNetwork() ; Receives Data DecodeGameNetData() ; Reads Received Data UpdateShot() UpdateTExplosion() UpdateSpark() UpdateImageExplosion() UpdateExplosion() ; Explosions over tanks UpdateFireLine() Draw_Tanks() Draw_Arena() ; _____________________ EndIf ;Flip limits your FPS to your monitors update Frekv, Flips False does not! If FLIPFALSE Flip False Else Flip ;) Wend ; - - - - M - A - I - N - - L - O - O - P - - -