From ae39b8e8611a7c70d23d8f3eacb5cc2dc956d551 Mon Sep 17 00:00:00 2001 From: panw Date: Thu, 19 Mar 2026 09:22:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=8B=B1=E9=9B=84=E8=A7=86=E5=9B=BE):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A1=80=E6=9D=A1=E8=BF=9B=E5=BA=A6=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E5=B9=B6=E4=BC=98=E5=8C=96=E6=98=BE=E7=A4=BA=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加对 hp_max 为 0 的防护,避免除零错误 - 使用 clamp 确保进度值在 0 到 1 之间 - 仅在血条减少时激活顶栏和播放抖动动画 - 血条增加时自动降低顶栏透明度 --- assets/script/game/hero/HeroViewComp.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index a761ffa1..b4e624d3 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -188,14 +188,19 @@ export class HeroViewComp extends CCComp { let hp_max=this.model.hp_max; // mLogger.log(this.debugMode, 'HeroViewComp', "hp_show",hp,hp_max) - let targetProgress = hp / hp_max; + let targetProgress = hp_max > 0 ? hp / hp_max : 0; + targetProgress = clamp(targetProgress, 0, 1); let hpNode = this.top_node.getChildByName("hp"); let hpProgressBar = hpNode.getComponent(ProgressBar); + const prevProgress = hpProgressBar.progress; if (targetProgress < hpProgressBar.progress) { this.activateTopBar(); this.playHpBarShake(); - hpProgressBar.progress = targetProgress; + } + hpProgressBar.progress = targetProgress; + if (targetProgress > prevProgress) { + this.setTopBarOpacity(false); } }