There is a spritebatch.DrawString (....) method for drawing text, this is how I draw the number of frames per second.
class FPS_Counter { private SpriteFont spriteFont; private float FPS = 0f; private float totalTime; private float displayFPS; public FPS_Counter(SpriteBatch batch, ContentManager content) { this.totalTime = 0f; this.displayFPS = 0f; } public void LoadContent(ContentManager content) { this.spriteFont = content.Load<SpriteFont>("Fonts/FPSSpriteFont"); } public void DrawFpsCount(GameTime gTime,SpriteBatch batch) { float elapsed = (float)gTime.ElapsedGameTime.TotalMilliseconds; totalTime += elapsed; if (totalTime >= 1000) { displayFPS = FPS; FPS = 0; totalTime = 0; } FPS++; batch.DrawString(this.spriteFont, this.displayFPS.ToString() + " FPS", new Vector2(10f, 10f), Color.White); }
source share