私は現在、C#、GDIを使用して2Dゲームエンジンを作り、簡単なフレームキャップをセットアップしています。ゲームは60fpsしかレンダリングできません。C#GDI Game Loop(FPS Counter)
私が知っている限り、コードに問題はありませんが、私は60fps以上のレンダリングをよりクリーンな方法で行いたいと思います。ここで
は、任意の助けがあなたのシナリオでは
public void Run()
{
window.Show();
window.Focus();
Initialize();
isRunning = true;
canRender = true;
timer = new Stopwatch();
timer.Start();
// the amount of milliseconds needed to pass before rendering next frame
double frameCapCounter = 16.666666;
while (isRunning)
{
Application.DoEvents();
if (window.Focused)
{
if (timer.ElapsedMilliseconds >= frameCapCounter)
{
canRender = true;
frames += 1; // update amount of frames
frameCapCounter += 16.666666; // increment counter
}
else
{
canRender = false;
}
// this is used to check if a second has passed, and if so
// we set the fps variable to the amount of frames rendered
// and reset all variables.
if (timer.ElapsedMilliseconds >= 1000)
{
fps = frames;
frames = 0;
frameCapCounter = 0;
timer.Restart();
}
Update();
LateUpdate();
if (canRender)
Render();
else
{
Thread.Sleep(1);
}
}
}
}
SlimDX(https://slimdx.org/docs/html/Managed_Message_Loop.htm)の人たちは、 'Application.DoEvents()'の代わりにこれを使っていました:https://blogs.msdn.microsoft.com/tmiller/ 2005/05/05/my-last-after-render-loops-hopefully / –