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