我曾幫助製作我的FPS跟蹤器,但我不明白爲什麼我必須在打印fps後添加previousTime += 1000;
。如果有人知道告訴我。另外如果你知道他爲什麼添加渲染兩次,請解釋一下。這裏是我的代碼:爲什麼我在我的FPS(幀每秒)跟蹤器中添加時間? (Java)
public void run()
{
int frames = 0;
double unprocessedSeconds = 0;
long previousTime = System.nanoTime();
double secondsPerTick = 1/60.0;
int tickCount = 0;
boolean ticked = false;
while(running)
{
//check ticker code
long currentTime = System.nanoTime();
long passedTime = currentTime - previousTime;
previousTime = currentTime;
unprocessedSeconds = passedTime/1000000000.0;
while(unprocessedSeconds > secondsPerTick)
{
tick();
unprocessedSeconds -= secondsPerTick;
ticked = true;
tickCount++;
if(tickCount % 60 == 0)
{
//System.out.println(frames + " fps");
previousTime += 1000;
fps = frames;
frames = 0;
}
}
if(ticked)
{
render();
frames++;
}
render();
frames++;
}
問問幫助你的人,因爲你可能不需要。 1000在納秒時間在數學上是不相關的(每秒有1.000.000.000 ns) – zapl