diff --git a/plugins/debug/debugPanel.js b/plugins/debug/debugPanel.js index 71510f0c40..754878037c 100644 --- a/plugins/debug/debugPanel.js +++ b/plugins/debug/debugPanel.js @@ -117,6 +117,15 @@ me.debug.renderHitBox = me.debug.renderHitBox || false; me.debug.renderVelocity = me.debug.renderVelocity || false; + // patch video.js + me.plugin.patch(me.timer, "update", function (context) { + // call the original me.game.draw function + this.parent(); + + // call the FPS counter + me.timer.countFPS(); + }); + // patch sprite.js me.plugin.patch(me.SpriteObject, "draw", function (context) { // call the original me.game.draw function diff --git a/src/debug/debug.js b/src/debug/debug.js index 88554ac60f..844ef7fe79 100644 --- a/src/debug/debug.js +++ b/src/debug/debug.js @@ -13,14 +13,6 @@ */ me.debug = { - /** - * enable the FPS counter
- * default value : false - * @type Boolean - * @memberOf me.debug - */ - displayFPS : false, - /** * render Collision Map layer
* default value : false diff --git a/src/video/video.js b/src/video/video.js index 536597e94a..d69e4552ed 100644 --- a/src/video/video.js +++ b/src/video/video.js @@ -24,8 +24,6 @@ ---------------------------------------------*/ //hold element to display fps - var htmlCounter = null; - var debug = false; var framecount = 0; var framedelta = 0; @@ -37,15 +35,6 @@ // define some step with some margin var minstep = (1000 / me.sys.fps) * 1.25; // IS IT NECESSARY? - /** - * draw the fps counter - * @ignore - */ - function draw(fps) { - htmlCounter.replaceChild(document.createTextNode("(" + fps + "/" - + me.sys.fps + " fps)"), htmlCounter.firstChild); - }; - /*--------------------------------------------- @@ -76,12 +65,6 @@ * @ignore */ api.init = function() { - // check if we have a fps counter display in the HTML - htmlCounter = document.getElementById("framecounter"); - if (htmlCounter !== null) { - me.debug.displayFPS = true; - } - // reset variables to initial state api.reset(); }; @@ -113,6 +96,24 @@ return now; }; + + /** + * compute the actual frame time and fps rate + * @name computeFPS + * @ignore + * @memberOf me.timer + * @function + */ + api.countFPS = function() { + framecount++; + framedelta += delta; + if (framecount % 10 == 0) { + this.fps = (~~((1000 * framecount) / framedelta)).clamp(0, me.sys.fps); + framedelta = 0; + framecount = 0; + } + }; + /** * update game tick * should be called once a frame @@ -124,20 +125,6 @@ delta = (now - last); - // only draw the FPS on in the HTML page - if (me.debug.displayFPS) { - framecount++; - framedelta += delta; - if (framecount % 10 == 0) { - this.fps = (~~((1000 * framecount) / framedelta)).clamp(0, me.sys.fps); - framedelta = 0; - framecount = 0; - } - // set the element in the HTML - if (htmlCounter !== null) { - draw(this.fps); - } - } // get the game tick api.tick = (delta > minstep && me.sys.interpolation) ? delta / step : 1; };