开发者

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

开发者 https://www.devze.com 2023-02-21 23:24 出处:网络
So there is great stats开发者_如何学C.js and I need it to give me its current FPS value. How to do such thig?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消