kubas126
kubas126

Reputation: 45

Monogame, XNA measure FPS

Please could me someone explain to me how does work this calculation? this formula works (its derivation)? I do not get it :(

framerate = (1 / gameTime.ElapsedGameTime.TotalSeconds);

From documentation I read that gameTime.ElapsedGameTime.TotalSeconds should return value Time since the last call to Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framework.GameTime)

wouldn't we want time since the last call to Draw() method?

Share Edit Undelete Flag

Upvotes: 1

Views: 203

Answers (1)

LeDreamer
LeDreamer

Reputation: 58

You can actually also use "gameTime.ElapsedGameTime.TotalSeconds" in the Draw() method.

protected override void Draw(GameTime gameTime)
{
     framerate = 1/(float)gameTime.ElapsedGameTime.TotalSeconds;

    // other draw code here ...
}

"gameTime.ElapsedGameTime.TotalSeconds" return the delta time since the last draw call. So dividing 1 by the delta time returns some kind of a frequency.

This is the formula for the frequency f

Our framerate is the "frequency" (f) and our delta time is the "period"(T).

Upvotes: 0

Related Questions