Rella Rella - 5 months ago 22
HTML Question

Javascript - stats.js (Hi-Res stats from MrDoob) - how to get current FPS?

So there is great stats.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 );

Answer

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().

Comments