Fps test (lag into account)

how would I figure out the fps of a program (taking lag into account)? I think @Revon used some delta time thing to make sure that in his game the ball moves the same speed, even with lag. I would think it’s around those lines, but I’m not sure how to do it.

Hi @BaronAWC,

You can use Javascript’s Date class to get the current time. Here’s a demo project:
FPSDemo5-22-2020_2-07-30PM.wick (2.2 KB)

The default script initializes project.now and project.fps:

let d = new Date();
project.now = d.getTime();
project.fps = 1;

Then the update script gets the change in time, called deltaTime, calculates the FPS, and displays them:

let d = new Date();
let deltaTime = d.getTime() - project.now;
project.now = d;
if (deltaTime !== 0) { //don't wanna divide by 0
let fps = 1000 / deltaTime;
//blend previous fps with current fps:
project.fps = project.fps * 0.9 + fps * 0.1;
}
duration_text.setText("Duration of frame: " + deltaTime + "ms");
fps_text.setText("FPS: " + Math.round(project.fps));

Hope this helps!

2 Likes