game-engine/modules/game-objects/fps-counter.js

21 lines
406 B
JavaScript

import { GameObject } from "./game-object.js";
export class FpsCounter extends GameObject {
constructor({ debug = false }) {
super({ debug });
this.fps = 0;
}
update(delta) {
this.fps = Math.floor(1 / delta);
}
render(ctx) {
if (!this.debug) {
return;
}
ctx.fillStyle = "Red";
ctx.font = "normal 12pt Arial";
ctx.fillText(this.fps + " fps", 5, 15);
}
}