summaryrefslogtreecommitdiff
path: root/src/engine/components/Sprite.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-02 04:02:20 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-03-02 04:02:20 -0700
commit4b9349b3f8bee21eb086cfd6e7668532a50e6048 (patch)
treefa3ae95f516d8ec10fb0de57886ff88410b6d11d /src/engine/components/Sprite.ts
parent06bb4177202b432d5f42141975ec82b5a8837f0e (diff)
downloadthe-abstraction-engine-4b9349b3f8bee21eb086cfd6e7668532a50e6048.tar.gz
the-abstraction-engine-4b9349b3f8bee21eb086cfd6e7668532a50e6048.zip
add text on lambda factory
Diffstat (limited to 'src/engine/components/Sprite.ts')
-rw-r--r--src/engine/components/Sprite.ts13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/engine/components/Sprite.ts b/src/engine/components/Sprite.ts
index 82d7011..c623bac 100644
--- a/src/engine/components/Sprite.ts
+++ b/src/engine/components/Sprite.ts
@@ -46,7 +46,7 @@ export class Sprite extends Component {
}
public draw(ctx: CanvasRenderingContext2D, drawArgs: DrawArgs) {
- const { center, rotation, tint, opacity } = drawArgs;
+ const { center, rotation, tint, opacity, backgroundText } = drawArgs;
ctx.save();
ctx.translate(center.x, center.y);
@@ -59,6 +59,17 @@ export class Sprite extends Component {
ctx.globalAlpha = opacity;
}
+ if (backgroundText) {
+ // draw text
+ const { fillStyle, font, textAlign, text } = backgroundText;
+ ctx.fillStyle = fillStyle;
+ ctx.font = font;
+ ctx.textAlign = textAlign;
+
+ const height = ctx.measureText("M").width;
+ ctx.fillText(text, center.x, center.y + height / 2);
+ }
+
ctx.drawImage(
this.sheet,
...this.getSpriteArgs(),