Making a frame counter is a pain in the ass. It’s almost ALWAYS the same code. So here’s a class to make it easy as humanly possible to add an FPS counter to your Monogame/XNA game.
Usage
To use, just include the CS file in your project and type this at the end of your games Draw call:
[sourcecode language=”csharp”]FPSCounter.Render(GraphicsDevice);
[/sourcecode]
That’s it. You have an FPS counter now. You can also time other things with it, by using the Tick function. For example, if you want to keep track of updates per second, put this in your Update fuction:
[sourcecode language=”csharp”]FPSCounter.Tick(0);
[/sourcecode]
Then you can draw your update counter by calling render with your counter index (0) as a parameter:
[sourcecode language=”csharp”]FPSCounter.Render(GraphicsDevice, 0);
[/sourcecode]
You can have as many different counters as you want this way, you can even position and color them using the extra parameters in the render function.
Download http://www.wonthelp.info/FPSCounter.cs