From 64a21c91a30772ef05c5b9d43c70181d9a46f60b Mon Sep 17 00:00:00 2001 From: Bill Rossi Date: Sat, 7 Jun 2025 10:57:41 -0400 Subject: [PATCH] Draw FPS --- src/game.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/game.js b/src/game.js index f253ef5..66bd791 100644 --- a/src/game.js +++ b/src/game.js @@ -44,9 +44,9 @@ export default class Game { } loop(timestamp) { - const dt = timestamp - this.timestamp + this.dt = timestamp - this.timestamp this.timestamp= timestamp - this.tick(dt) + this.tick(this.dt) this.draw() requestAnimationFrame(this.loop.bind(this)) @@ -67,5 +67,16 @@ export default class Game { this.currentRoom.draw(ctx) this.actors.forEach(actor => actor.draw(ctx)) this.message?.draw(ctx) + this.drawFps(ctx) + } + + drawFps(ctx) { + ctx.fillStyle = "white" + ctx.fillRect(0, 0, 25, 20) + ctx.strokeStyle = "black" + ctx.textBaseline = "top" + ctx.font = "bold 20px serif" + ctx.fillText(Math.round(1000 / this.dt), 0, 0) + ctx.strokeText(Math.round(1000 / this.dt), 0, 0) } }