add drawText

This commit is contained in:
Reimar 2025-10-14 15:54:11 +02:00
parent dac13a4973
commit 2e371538fa

View File

@ -129,6 +129,28 @@ export class Gamelib {
cx.fillRect(x, y, width, height);
}
drawText(x, y, text, style = {}) {
const cx = this.cx;
cx.font = [
style.fontWeight ?? null,
style.fontStyle ?? null,
`${style.fontSize ?? 24}px`,
style.fontFamily ?? "sans-serif",
]
.filter((val) => val)
.join(" ");
console.log(cx.font);
cx.textAlign = style.align ?? "left";
cx.textBaseline = style.baseline ?? "alphabetic";
cx.direction = style.direction ?? "ltr";
cx.fillStyle = style.color ?? "white";
cx.fillText(text, x, y);
}
getAdapter() {
return new GamelibAdapter(this);
}
@ -212,4 +234,8 @@ export class GamelibAdapter {
drawRect(x, y, width, height, color) {
this.gamelib.drawRect(x, y, width, height, color);
}
drawText(x, y, text, style = {}) {
this.gamelib.drawText(x, y, text, style);
}
}