add drawText
This commit is contained in:
parent
dac13a4973
commit
2e371538fa
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user