PCでゲーム(c#/ XNA 4.0を使用して開発)を実行すると、ランダムなフレームレートの増加が発生します。これらの増加は、ゲームプレイ中に途切れ途切れの影響を引き起こします。これは通常、ゲームの起動時に発生し、煩わしいほど頻繁に発生します。 。
たとえば、私のFPSカウンターは62から85にジャンプし(わずかなスタッターを引き起こします)、62に戻り、62/63 FPSの間に3分間一貫して留まり、78にジャンプしてから再び62/63に戻ります。FPSが実際に60を下回ることはめったにありません。
何が起こっているのかについてのアイデアはありますか?
編集-以下に私のFPSコードを追加しました(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);
}
}
}
明確にするために、プロジェクト全体を追加せずに、これに関するコードを追加する方法がわかりません。しかし、私は確かにもっと情報を追加することができます。私のGameクラスに加えて、XNAのGameComponent機能を使用する他の2つのクラス(SpriteManager、FontManager)があり、それぞれに独自のLoad Content、Update、およびDrawメソッドが含まれています(以下の例)。
public class SpriteManager : Microsoft.Xna.Framework.DrawableGameComponent
{
//Manager code
}
public class FontManager : Microsoft.Xna.Framework.DrawableGameComponent
{
//Manager code
}
この追加情報がお役に立てば幸いです。
編集終了