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

22 lines
406 B
JavaScript
Raw Normal View History

2024-09-14 18:38:50 -05:00
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);
}
}