Javascript - stats.js (Hi-Res stats from MrDoob) - how to get current FPS?
So there is great stats开发者_如何学C.js and I need it to give me its current FPS value. How to do such thig?
So I try
stats.domElement.style.position = 'absolute';
stats.domElement.style.left = '0px';
stats.domElement.style.top = '0px';
$('body').append(stats.domElement );
setInterval( function () { stats.update();}, 1000 / 60 );
setInterval(function () { if(stats._fps <= 50){
// Do stuff for slow guys
}}, 1000 );
The Stats object only has two public properties: domElement
and update()
.
To retrieve the FPS, you would have to add a getFPS
function to the object returned by the Status constructor, like this:
return {
domElement: _container,
getFPS: function () {
return _fps;
},
update: function () {
// ...
}
};
That way, you can retrieve the FPS value using stats.getFPS()
.
精彩评论