From 34287a3724ce2c48f3fc2923f7e9a1000c80fa78 Mon Sep 17 00:00:00 2001 From: Philipp Abraham Date: Sun, 16 Feb 2014 23:48:51 +0100 Subject: [PATCH] draw FPS when location.hash contains 'fps' --- src/game.js | 10 +++++++++- src/main.js | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/game.js b/src/game.js index 66914a0..50e04ec 100644 --- a/src/game.js +++ b/src/game.js @@ -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; @@ -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); @@ -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 { diff --git a/src/main.js b/src/main.js index b789ce7..8230c89 100644 --- a/src/main.js +++ b/src/main.js @@ -40,7 +40,7 @@ require([ game.lastTickTime = time; game.tick(delta); - game.render(ctx); + game.render(ctx, delta); window.requestAnimationFrame(mainLoop); }