This commit is contained in:
Bill Rossi 2025-06-07 10:57:41 -04:00
parent d14864c604
commit 64a21c91a3

View File

@ -44,9 +44,9 @@ export default class Game {
} }
loop(timestamp) { loop(timestamp) {
const dt = timestamp - this.timestamp this.dt = timestamp - this.timestamp
this.timestamp= timestamp this.timestamp= timestamp
this.tick(dt) this.tick(this.dt)
this.draw() this.draw()
requestAnimationFrame(this.loop.bind(this)) requestAnimationFrame(this.loop.bind(this))
@ -67,5 +67,16 @@ export default class Game {
this.currentRoom.draw(ctx) this.currentRoom.draw(ctx)
this.actors.forEach(actor => actor.draw(ctx)) this.actors.forEach(actor => actor.draw(ctx))
this.message?.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)
} }
} }