Private NextCount as Int32 = Environment.TickCount
Private FPS as Int16
Public CurrentFPS as Int16
Public Sub CountFPS()
If Environment.TickCount > NextCount Then
CurrentFPS = FPS + 1
FPS = 0
NextCount = Environment.TickCount + 1000
Else
FPS += 1
End If
End Sub
Private NextCount As Int32 = Environment.TickCount 'Time until 1 second has past
Private FPS As Int16 'variable to count frames(32767 Hz max FPS count)
Public CurrentFPS As Int16 'Total FPS count from the last second
Public Sub CountFPS()
If Environment.TickCount > NextCount Then 'If current time has past time for the end of the second
CurrentFPS = FPS + 1 'Change the returnable value
FPS = 0 'Reset the counter for next second
NextCount = Environment.TickCount + 1000 'update time till next second
Else 'if it has not been 1 second yet
FPS += 1 'just add 1 to the counter
End If
End Sub
Public Sub GameLoop()
Do until bRunning = False
Back.DrawText 0, 0, "Current FPS: " & CurrentFPS.ToString(), False
Primary.Flip Nothing, .... (Use .NOVSYNC to ignore Windows' max Hz)
CountFPS() 'Update the FPS counter for this render pass
Application.DoEvents()
Loop
End Sub