检查JS中的FPS? [英] Check FPS in JS?

查看:716
本文介绍了检查JS中的FPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查我的JavaScript的fps?我使用这个循环:

How would I check the fps of my javascript? I'm using this to loop:

gameloopId = setInterval(gameLoop, 10);


推荐答案

gameLoop ,查看上一个循环中的 new Date new Date 之间的差异变量)。

换句话说:

In gameLoop, look at the difference between new Date and new Date from the last loop (store it in a variable).
In other words:

var lastLoop = new Date;
function gameLoop() { 
    var thisLoop = new Date;
    var fps = 1000 / (thisLoop - lastLoop);
    lastLoop = thisLoop;
    ...
}

thisLoop - lastLoop 是两个循环之间传递的毫秒数。

thisLoop - lastLoop is the number of milliseconds that passed between the two loops.

这篇关于检查JS中的FPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆