Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

made the framerate counter dumb but more accurate

  • Loading branch information...
commit 17929c9f7dfe7e4ada6daf14a88d939b87c6dc1b 1 parent ce7fc05
@dmcinnes authored
Showing with 10 additions and 2 deletions.
  1. +10 −2 game.js
View
12 game.js
@@ -1092,6 +1092,8 @@ $(function () {
var i, j = 0;
var showFramerate = false;
var avgFramerate = 0;
+ var frameCount = 0;
+ var elapsedCounter = 0;
var lastFrame = Date.now();
var thisFrame;
@@ -1148,10 +1150,16 @@ $(function () {
}
if (showFramerate) {
- avgFramerate = Math.round((avgFramerate * 24 + (1000 / elapsed))
- / 25);
Text.renderText(''+avgFramerate, 24, Game.canvasWidth - 38, Game.canvasHeight - 2);
}
+
+ frameCount++;
+ elapsedCounter += elapsed;
+ if (elapsedCounter > 1000) {
+ elapsedCounter -= 1000;
+ avgFramerate = frameCount;
+ frameCount = 0;
+ }
};
var mainLoopId = setInterval(mainLoop, 25);
Please sign in to comment.
Something went wrong with that request. Please try again.