summaryrefslogtreecommitdiff
path: root/src/engine/components/Sprite.ts
diff options
context:
space:
mode:
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(),