I"m experiencing random framerate increases when I run my game (developed using c#/XNA 4.0) on the PC. These increases are causing a stuttering affect during gameplay. It usually happens when the game starts up and is just frequent enough to be annoying.
For example - my FPS counter will jump from 62 to 85 (causing a slight stutter) then back to 62 and stay consistently between 62/63 FPS for three minutes and then jump to 78 then go back to 62/63 again. It's rare for the FPS to actually drop below 60.
Any ideas of what is going on?
Edit - Added my FPS code below (02.06.2013)
namespace Game
{
class FPSDebuggerFont : Font
{
//int totalScore;
//FramesPerSecond (FPS) debug variables
int totalFrames = 0;
int fps = 0;
int elpaseMilliseconds = 1000;
string fpsText;
public FPSDebuggerFont(SpriteFont scoreFont, String text, Vector2 pos, Color color, float scale, float layerDepth)
: base(scoreFont, text, pos, color, scale, layerDepth)
{
}
public void FPSTime(GameTime gameTime)
{
//Algorithm for FPS debugging
elpaseMilliseconds -= (float)gameTime.ElapsedGameTime.Milliseconds;
if (elpaseMilliseconds < 0)
{
//FPS debugg info
fps = totalFrames;
elpaseMilliseconds = 1000;
totalFrames = 0;
}
}
public override void Update(GameTime gameTime)
{
FPSTime(gameTime);
}
public override void Draw(GameTime gameTime, SpriteBatch sB)
{
totalFrames++;
fpsText = "Frames Per Second: " + fps;
sB.DrawString(scoreFont, fpsText, pos, color, 0, Vector2.Zero, scale, SpriteEffects.None, layerDepth);
}
}
}
For clarification purposes, I'm not sure how I can add anymore code regarding this without adding my entire project. But I can certainly add more information; along with my Game class I have two other classes (SpriteManager, FontManager) using the GameComponent functionality of XNA, each containing their own Load Content, Update, and Draw methods, example below;
public class SpriteManager : Microsoft.Xna.Framework.DrawableGameComponent
{
//Manager code
}
public class FontManager : Microsoft.Xna.Framework.DrawableGameComponent
{
//Manager code
}
Hopefully this additional information helps.
End Edit