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); } }