What is the formula used to calculate FPS in a game?

Asked

Viewed 1,436 times

4

I’m creating a game in java using lwjgl3, I’ve seen many algorithms but all are different from each other.

So simplifying my code would be like this:

start();

while(running){
    update();
    render();
}

exit();

What formula could I use to calculate the fps of the game?

  • 1

    Does this resolve https://tutorialedge.net/lwjgl-3-fps-main-game-loop ? I will not formulate an answer because I do not understand of lwjgl, but if you test yourself can answer your own question :)

  • Search something called Simple Moving Average - SMA. According to OANDA: "SMA means simple Moving Average (simple moving average). Helps smooth the price curve for a better identification of the trend. The longer the selected SMA period, the smoother the curve". Obviously, exchange "prices" there for "frames per second". : ) I also will not put an answer for the same reason William.

  • @Guilhermenascimento was what I was looking for, because I only found tutorials on lwjgl 2.

1 answer

2


The table rate per second (FPS or QPS) may be calculated as follows::

public void start() {
    lastFPS = getTime();
}

public void updateFPS() {
    if (getTime() - lastFPS > 1000) {
        Display.setTitle("FPS: " + fps); 
        fps = 0; //reseta o contador de FPS
        lastFPS += 1000; //adiciona um segundo
    }
    fps++;
}

The representation of FPS is simple, it’s how many frames were displayed in a single second. The frame rate per second being 30, means that in a second 30 frames were displayed.

The formula, in a basic representation, would be: FPS = (number of frames) / (number of seconds). For example, if in 120 seconds were displayed 6400 frames, our FPS would be 53.333 (6400 / 120).

The Display.setTitle(String title) is to simplify by showing the counter in the window title.

More information on documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.