diff --git a/src/gamelib.js b/src/gamelib.js index 8d2b138..cdcf6b5 100644 --- a/src/gamelib.js +++ b/src/gamelib.js @@ -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); + } }