fix(英雄视图): 修复血条进度计算并优化显示逻辑
- 添加对 hp_max 为 0 的防护,避免除零错误 - 使用 clamp 确保进度值在 0 到 1 之间 - 仅在血条减少时激活顶栏和播放抖动动画 - 血条增加时自动降低顶栏透明度
This commit is contained in:
@@ -188,14 +188,19 @@ export class HeroViewComp extends CCComp {
|
|||||||
let hp_max=this.model.hp_max;
|
let hp_max=this.model.hp_max;
|
||||||
// mLogger.log(this.debugMode, 'HeroViewComp', "hp_show",hp,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 hpNode = this.top_node.getChildByName("hp");
|
||||||
let hpProgressBar = hpNode.getComponent(ProgressBar);
|
let hpProgressBar = hpNode.getComponent(ProgressBar);
|
||||||
|
|
||||||
|
const prevProgress = hpProgressBar.progress;
|
||||||
if (targetProgress < hpProgressBar.progress) {
|
if (targetProgress < hpProgressBar.progress) {
|
||||||
this.activateTopBar();
|
this.activateTopBar();
|
||||||
this.playHpBarShake();
|
this.playHpBarShake();
|
||||||
hpProgressBar.progress = targetProgress;
|
}
|
||||||
|
hpProgressBar.progress = targetProgress;
|
||||||
|
if (targetProgress > prevProgress) {
|
||||||
|
this.setTopBarOpacity(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user