Hey,
For the past few months I’ve been messing around on a little project of mine and now I’m just getting to the point where I can start using the game loop again. I haven’t even looked at this loop in a few months so I’m not sure how to fix it up the way I want just yet. Could someone explain how I could go about limiting the FPS to stop it from running at a few thousand FPS?
public void run() {
long lastTime = System.nanoTime();
long timer = System.currentTimeMillis();
final double NANO_SECONDS = 1000000000.0 / 60.0;
double delta = 0.0;
int frames = 0; // (FPS)Counts how many frames can be rendered per second.
int updates = 0; // Counts how many times update(); can be called per second.
new TESTING();
while (running) {
long now = System.nanoTime();
delta += (now - lastTime) / NANO_SECONDS;
lastTime = now;
while(delta >= 1)
{
updateLogic();
updates++;
delta--;
}
renderScreen();
frames++;
if((System.currentTimeMillis() - timer) > 1000)
{
timer += 1000;
FRAME.setTitle(updates + "UPS, " + frames + "FPS");
updates = 0;
frames = 0;
}
}
stop();
}
I’m fairly sure that I based this game loop off of TheCherno’s youtube tutorials but it was quite a while back so I’m not sure.
Thanks in advance for any replies.