display all sprites for testing

This commit is contained in:
anna 2022-10-25 22:57:42 +02:00
parent f93b50e870
commit 8447313106
Signed by: fef
GPG key ID: EC22E476DC2D3D84

View file

@ -1,13 +1,25 @@
import {fetchPalette, Palette} from "./sprite";
export class App { export class App {
private canvas: HTMLCanvasElement; private canvas: HTMLCanvasElement;
private readonly context: CanvasRenderingContext2D;
private lastTime: DOMHighResTimeStamp = 0; private lastTime: DOMHighResTimeStamp = 0;
private isRunning: boolean = false; private isRunning: boolean = false;
private palette?: Palette;
public constructor(canvas: HTMLCanvasElement) { public constructor(canvas: HTMLCanvasElement) {
this.canvas = canvas; this.canvas = canvas;
this.updateSize(window.innerWidth, window.innerHeight); const context = canvas.getContext("2d");
if (context === null) {
throw new Error("Failed to get 2D context");
}
context.imageSmoothingEnabled = false; // pixelart
this.context = context;
document.onresize = () => this.updateSize(window.innerWidth, window.innerHeight); this.updateSize(window.innerWidth, window.innerHeight);
window.onresize = () => this.updateSize(window.innerWidth, window.innerHeight);
fetchPalette("").then(p => this.palette = p);
} }
public run() { public run() {
@ -20,7 +32,16 @@ export class App {
} }
private draw(time: DOMHighResTimeStamp) { private draw(time: DOMHighResTimeStamp) {
// TODO: actually draw stuff this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
if (this.palette) {
let x = 0;
for (let s of this.palette.sprites) {
for (let y = 0; y < 4; y++) {
s.draw(this.context, y * 128, x, y);
}
x += 128;
}
}
this.lastTime = time; this.lastTime = time;
if (this.isRunning) { if (this.isRunning) {