-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext-graphic.ts
29 lines (27 loc) · 1.04 KB
/
text-graphic.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Text from "@dcgw/excalibur-text";
import {BaseAlign, Color, TextAlign, Vector} from "excalibur";
export interface TextOptions {
readonly text?: string | undefined;
readonly fontSize?: number | undefined;
readonly textAlign?: TextAlign | undefined;
readonly color?: Color | undefined;
readonly opacity?: number | undefined;
readonly outlineColor?: Color | undefined;
readonly shadowBlurRadius?: number;
}
export function textGraphic(options: TextOptions): Text {
return new Text({
origin: Vector.Zero,
text: options.text ?? "",
fontFamily: "Strait",
fontSize: options.fontSize ?? 48,
textAlign: options.textAlign ?? TextAlign.Left,
baseAlign: BaseAlign.Top,
color: options.color ?? Color.White,
outlineColor: options.outlineColor ?? Color.fromRGB(0, 0, 0, 0.5),
outlineWidth: 1,
shadowColor: Color.Black,
shadowBlurRadius: options.shadowBlurRadius ?? 2,
...(options.opacity == null ? {} : {opacity: options.opacity})
});
}