Draw FPS
This commit is contained in:
parent
d14864c604
commit
64a21c91a3
15
src/game.js
15
src/game.js
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user