November 28, 2020, 01:44:27 PM

Author Topic: [bb] ShowFPS by Captain Wicker (crazy hillbilly) [ 1+ years ago ]  (Read 383 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : ShowFPS
Author : Captain Wicker (crazy hillbilly)
Posted : 1+ years ago

Description : A simple code to show the screen frame rate

Code :
Code: BlitzBasic
  1. Function ShowFPS(x#,y#)
  2. timenow=MilliSecs()
  3.  
  4. If timenow>telltime Then
  5.         telltime=timenow+1000
  6.         getframes=frames
  7.         frames=0
  8. Else
  9.         frames=frames+1
  10. EndIf
  11.         Text x#,y#,getframes
  12. End Function


Comments :


Captain Wicker (crazy hillbilly)(Posted 1+ years ago)

 Use this in your main program loop like this:[bbcode]While Not KeyHit(1);Cls() ;in blitz+;UpdateWorld() ;in blitz3d;RenderWorld() ;in blitz3dFlip()ShowFPS(10,10)Wend[/bbcode]It would be nice if we could use syntax highlighting when submitting code into the archives.


misth(Posted 1+ years ago)

 Hmm, didn't work in BlitzPlus. I guess you'll need globals for your function to work, like mine:
Code: [Select]
Graphics 640,480,0,2

While Not KeyHit(1)
Cls()

a# = a + 1.0

For i = 0 To 36
x# = 320.0 + Cos(a + (i* 10.0)) * 100.0
y# = 240.0 - Sin(a + (i* 10.0)) * 100.0

Oval x-5, y-5, 10,10
Next

Text 0,0,FPS()

Flip(Not KeyDown(57))
Wend

Global gFPS, gRenders, gFPSTimer
Function FPS()
If MilliSecs() > gFPSTimer Then
gFPS = gRenders
gRenders = 0
gFPSTimer = MilliSecs() + 1000
Else
gRenders = gRenders + 1
End If

Return gFPS
End Function


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal