Page 1 of 1

Display FPS in Game

Posted: Fri Sep 03, 2010 5:13 am
by J. Baker

Code: Select all

;before Repeat

  FPSCounter = 0
  OneSecond = 1
  
;after Repeat
  
  Repeat
    
    If FlipBuffers()
       FPSCounter +1
    EndIf
     
    If OneSecond = 1
        StartTime = ElapsedMilliseconds()
        OneSecond = 0
    EndIf   
    
      ElapsedTime = ElapsedMilliseconds()-StartTime
    
    If ElapsedTime >= 1000
        FinalFPS = FPSCounter 
         FPSCounter = 0
        OneSecond = 1
    EndIf
     
      StartDrawing(ScreenOutput())
       DrawingMode(#PB_2DDrawing_Default)
        DrawText(10, 0, "FPS " + Str(FinalFPS), RGB(255, 255, 255))
      StopDrawing()

Re: Display FPS in Game

Posted: Fri Sep 03, 2010 1:02 pm
by infratec
Hi J.

hmmm,

first I would replace

Code: Select all

If ElapsedTime = 1000
with

Code: Select all

If ElapsedTime >= 1000
I think it is clear why.

But in general I think it is better to use a window timer for waiting one second.

Bernd

Re: Display FPS in Game

Posted: Fri Sep 03, 2010 2:10 pm
by J. Baker
You are correct, my mistake. I updated the code.

I don't think AddWindowTimer() works in a full screen game as there's no WindowEvent().