actually center text
This commit is contained in:
parent
413149172b
commit
09267bcd12
|
|
@ -97,6 +97,6 @@ export function draw(ctx: GameContext) {
|
||||||
c.restore()
|
c.restore()
|
||||||
|
|
||||||
if (dead) {
|
if (dead) {
|
||||||
ctx.centerText("GAME OVER", ctx.height / 2, "red", 50)
|
ctx.centerText("GAME OVER", "red", 50)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,18 +20,18 @@ export class GameContext {
|
||||||
c.restore()
|
c.restore()
|
||||||
}
|
}
|
||||||
|
|
||||||
centerText(msg: string, y: number, color = "black", size = 16, font = "C64ProMono") {
|
centerText(msg: string, color = "black", size = 16, font = "C64ProMono") {
|
||||||
const c = this.ctx
|
const c = this.ctx
|
||||||
c.save()
|
c.save()
|
||||||
c.fillStyle = color
|
c.fillStyle = color
|
||||||
c.font = `${size}px ${font}`
|
c.font = `${size}px ${font}`
|
||||||
c.textBaseline = "middle"
|
c.textBaseline = "middle"
|
||||||
const metrics = c.measureText(msg)
|
c.textAlign = "center"
|
||||||
const x = (this.width - metrics.width) / 2
|
c.fillText(msg, this.width / 2, this.height / 2)
|
||||||
c.fillText(msg, x, y)
|
|
||||||
c.restore()
|
c.restore()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
circ(x: number, y: number, r: number, color = "black") {
|
circ(x: number, y: number, r: number, color = "black") {
|
||||||
const c = this.ctx
|
const c = this.ctx
|
||||||
c.save()
|
c.save()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user