First Commit

This commit is contained in:
2025-08-07 20:20:36 +02:00
parent 025d539fc5
commit 21f637fcec
37 changed files with 4620 additions and 0 deletions

36
src/classes/Tile.ts Normal file
View File

@@ -0,0 +1,36 @@
export class Tile {
x: number;
y: number;
tilesheet: HTMLImageElement;
tile: HTMLImageElement | null = null;
fullyTransparent: boolean = true;
constructor(x: number, y: number, tilesheet: HTMLImageElement) {
this.x = x;
this.y = y;
this.tilesheet = tilesheet;
}
async loadTile() {
const canvas = new OffscreenCanvas(16, 16);
const ctx = canvas.getContext("2d");
ctx?.drawImage(this.tilesheet, this.x, this.y, 16, 16, 0, 0, 16, 16);
const img = document.createElement("img");
const blob = await canvas.convertToBlob();
img.src = URL.createObjectURL(blob);
// img.loading = "eager";
this.tile = img;
if (ctx) {
const data = ctx.getImageData(0, 0, 16, 16).data;
for (let i = 3; i < data.length; i += 4) {
if (data[i] !== 0) {
this.fullyTransparent = false;
break;
}
}
}
}
}