Created
November 14, 2018 08:22
-
-
Save baobao/bceee68175369715ed227a8a676d6f20 to your computer and use it in GitHub Desktop.
FPSを意識したループ処理の部分コード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Loop() | |
{ | |
// StopWatchの再スタート | |
sw.Restart(); | |
Draw(); | |
// 描画処理経過時間(ミリ秒)を取得 | |
var elapsedMilliSec = sw.ElapsedMilliseconds; | |
// fpsをミリ秒に変換して、経過時間の差分をSleepTimeとする | |
var sleepTime = 1000 / fps - elapsedMilliSec; | |
if (sleepTime > 0) | |
{ | |
// SleepTimeが0未満ならフレーム落ち | |
// スレッドを待機させてFPSを再現する | |
Thread.Sleep((int)sleepTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment