Contact

 
Google
Web www.alanphipps.com

 
   
 
   
www.alanphipps.com

.: The Framerate Counter

 
 

 

A games framerate is the number of times the screen is refreshed every second. The lower a framerate the more chance that the game will stutter and display graphical distortions. Keeping the framerate above 40 is good but keeping it above 25 is a must. So with this in mind it would be good if we could display the framerate when the game is running, this is done as follows:

Open your project or download the one from Tutorial 2. Once open right-click the project name in the solution explorer and select Add Class. name this class Framerate.

XNA in VB.NET - Framerate Counter Class

The code for this new class is as follows:

Public Class FrameRate

Public Shared Function CalculateFrameRate() As Integer

If System.Environment.TickCount - lastTick >= 1000 Then
lastFrameRate = frameRate
frameRate = 0
lastTick = System.Environment.TickCount
End If

frameRate += 1

Return lastFrameRate

End Function 'CalculateFrameRate

Private Shared lastTick As Integer
Private Shared lastFrameRate As Integer
Private Shared frameRate As Integer

End Class

 

Then in the OnPaint Method of your game's main form type this:

'Display framerate on window title bar
Me.Text = String.Format("The framerate is {0}", FrameRate.CalculateFrameRate()

Thats it, now run your program and the framerate will be displayed i the title bar:

XNA in VB.NET - Framerate shown in titlebar

Now you can return to the tutorials page and work through the next tutorial.

 

Framerate Counter Source Code - 40Kb

 

     
 
 
     

 

Web site contents © Copyright Alan Phipps 2006, All rights reserved.
Website templates
   
 
 

 

__PayPal

PayPal - Any Amount is Welcome
 
Please Donate to the Nvidia Geforce Go 7950 GTX Fund, All donations welcome. Thanks.

 

XNA in C#

 
 

Games at Amazon