Skip to content

Commit

Permalink
draw FPS when location.hash contains 'fps'
Browse files Browse the repository at this point in the history
  • Loading branch information
master-lincoln committed Feb 16, 2014
1 parent ed820cc commit 34287a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ define(['bird', 'pipe', 'score', 'difficulty', '../lib/promise-0.1.1.min'], func

var pipes = [];

var drawFps = (location.hash.indexOf('fps') !== -1);
var flash = false;
var showIntroScreen = true;
var levelPassed = false;
Expand Down Expand Up @@ -213,7 +214,7 @@ define(['bird', 'pipe', 'score', 'difficulty', '../lib/promise-0.1.1.min'], func
drawImage('tutorial', 200, 200, ctx);
}

function render(ctx) {
function render(ctx, delta) {
ctx.save();
drawBG(ctx);
ctx.translate(-~~offsetX, 0);
Expand All @@ -235,6 +236,13 @@ define(['bird', 'pipe', 'score', 'difficulty', '../lib/promise-0.1.1.min'], func

if (levelPassed)
drawNextLevelText(ctx);

if (drawFps) {
var fps = ~~(1000 / delta);
ctx.font = "10px sans-serif";
ctx.fillStyle = "black";
ctx.fillText(fps.toString(), game.SIZE[0]-20, 10);
}
}

return {
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require([
game.lastTickTime = time;

game.tick(delta);
game.render(ctx);
game.render(ctx, delta);

window.requestAnimationFrame(mainLoop);
}
Expand Down

0 comments on commit 34287a3

Please sign in to comment.