mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-12-25 01:39:23 +01:00
added an FPS counter to the demos
This commit is contained in:
parent
ab9e9f2a1b
commit
93a77b882f
1 changed files with 13 additions and 0 deletions
|
@ -14,6 +14,9 @@ namespace Demos {
|
|||
|
||||
private static readonly Dictionary<string, Func<MlemGame, Demo>> Demos = new Dictionary<string, Func<MlemGame, Demo>>();
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue