From 9922a898f806e53faa63a5d82d0f498e74f55de3 Mon Sep 17 00:00:00 2001 From: Florrie Date: Mon, 20 Aug 2018 11:05:21 -0300 Subject: Don't let HP bars go off screen Also a tweak to action label rendering --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 237a9e3..79d7d7f 100644 --- a/index.js +++ b/index.js @@ -941,7 +941,7 @@ class Battle { ctx.font = '5px pixel-font' const width = ctx.measureText(label).width + 4 - const x = Math.round(sprite.x - sprite.canvas.width / 2 - width / 2) + const x = Math.round(sprite.x - width / 2) const y = Math.round(sprite.y - sprite.canvas.height / 2) let textFillStyle @@ -1030,9 +1030,9 @@ class Battle { for (const { x, y, battleCharacter } of overlayHPBars) { const hpBar = battleCharacter.hpBar - const drawX = Math.round(x - hpBar.canvas.width / 2) - const drawY = Math.round(y - hpBar.canvas.height) hpBar.draw() + const drawX = Math.max(10 + hpBar.labelCanvas.width, Math.round(x - hpBar.canvas.width / 2)) + const drawY = Math.max(10, Math.round(y - hpBar.canvas.height)) ctx.drawImage(hpBar.canvas, drawX, drawY) ctx.drawImage(hpBar.labelCanvas, drawX - hpBar.labelCanvas.width - 2, drawY - 1) } -- cgit 1.3.0-6-gf8a5