From 93a77b882fac224338090fb7cdd314ea766a9f5f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 20 Feb 2020 17:57:14 +0100 Subject: [PATCH] added an FPS counter to the demos --- Demos/GameImpl.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Demos/GameImpl.cs b/Demos/GameImpl.cs index 197acdc..22396af 100644 --- a/Demos/GameImpl.cs +++ b/Demos/GameImpl.cs @@ -14,6 +14,9 @@ namespace Demos { private static readonly Dictionary> Demos = new Dictionary>(); private Demo activeDemo; + private double fpsTime; + private int lastFps; + private int fpsCounter; static GameImpl() { Demos.Add("Ui", game => new UiDemo(game)); @@ -68,6 +71,8 @@ namespace Demos { PositionOffset = new Vector2(0, 1) }); } + + this.UiSystem.Add("Fps", new Paragraph(Anchor.TopLeft, 1, p => "FPS: " + this.lastFps)); } protected override void DoDraw(GameTime gameTime) { @@ -77,6 +82,14 @@ namespace Demos { this.GraphicsDevice.Clear(Color.CornflowerBlue); } base.DoDraw(gameTime); + + this.fpsCounter++; + this.fpsTime += gameTime.ElapsedGameTime.TotalSeconds; + if (this.fpsTime >= 1) { + this.fpsTime -= 1; + this.lastFps = this.fpsCounter; + this.fpsCounter = 0; + } } protected override void DoUpdate(GameTime gameTime) {