« get me outta code hell

Don't let HP bars go off screen - csb-game - Pixelly spin-off of the Command Synergy Battle system used in Final Fantasy XIII
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-08-20 11:05:21 -0300
committerFlorrie <towerofnix@gmail.com>2018-08-20 11:05:23 -0300
commit9922a898f806e53faa63a5d82d0f498e74f55de3 (patch)
treee1afeec1f1c7d89b9870fb89258b4887f9861c94
parent267c3ea764a851fe50d24feaf0d8a9612c14af43 (diff)
Don't let HP bars go off screen
Also a tweak to action label rendering
-rw-r--r--index.js6
1 files 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)
     }