You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
987 B
TypeScript
39 lines
987 B
TypeScript
export class App {
|
|
private canvas: HTMLCanvasElement;
|
|
private lastTime: DOMHighResTimeStamp = 0;
|
|
private isRunning: boolean = false;
|
|
|
|
public constructor(canvas: HTMLCanvasElement) {
|
|
this.canvas = canvas;
|
|
this.updateSize(window.innerWidth, window.innerHeight);
|
|
|
|
document.onresize = () => this.updateSize(window.innerWidth, window.innerHeight);
|
|
}
|
|
|
|
public run() {
|
|
this.isRunning = true;
|
|
this.draw(this.lastTime);
|
|
}
|
|
|
|
public stop() {
|
|
this.isRunning = false;
|
|
}
|
|
|
|
private draw(time: DOMHighResTimeStamp) {
|
|
// TODO: actually draw stuff
|
|
|
|
this.lastTime = time;
|
|
if (this.isRunning) {
|
|
window.requestAnimationFrame(t => this.draw(t));
|
|
}
|
|
}
|
|
|
|
private updateSize(width: number, height: number) {
|
|
this.canvas.width = width;
|
|
this.canvas.height = height;
|
|
}
|
|
}
|
|
|
|
const app = new App(document.getElementById("render") as HTMLCanvasElement);
|
|
app.run();
|