Answer the question
In order to leave comments, you need to log in
How to release frame counter - FPS in CANVAS game?
How to release frame counter - FPS in CANVAS game?
Answer the question
In order to leave comments, you need to log in
With requestAnimationFrame:
const times = [];
let fps;
function refreshLoop() {
window.requestAnimationFrame(() => {
const now = performance.now();
while (times.length > 0 && times[0] <= now - 1000) {
times.shift();
}
times.push(now);
fps = times.length;
refreshLoop();
});
}
refreshLoop();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question