From f9012458d8e07928fa10c184039d74201a7874c9 Mon Sep 17 00:00:00 2001 From: panw Date: Tue, 24 Mar 2026 16:26:45 +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=E6=8A=A4=E7=9B=BE=E6=98=BE=E7=A4=BA=E6=97=B6?= =?UTF-8?q?=E9=A1=B6=E9=83=A8=E8=A1=80=E6=9D=A1=E9=9A=90=E8=97=8F=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调整顶部血条显示逻辑,将透明度控制改为显隐控制,确保护盾存在时血条始终可见。同时修复了护盾更新时未正确触发血条显示的问题,并优化了满血无护盾时的自动隐藏逻辑。 --- assets/script/game/hero/HeroViewComp.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index 642a9f44..b3c0e964 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -115,13 +115,12 @@ export class HeroViewComp extends CCComp { private initUINodes() { this.top_node = this.node.getChildByName("top"); this.topOpacity = this.top_node.getComponent(UIOpacity) || this.top_node.addComponent(UIOpacity); + this.top_node.setPosition(0, 100, 0); this.topBasePos = this.top_node.position.clone(); const hpNode = this.top_node.getChildByName("hp"); if(this.model.fac==FacSet.HERO){ hpNode.getChildByName("Bar").getComponent(Sprite).color=new Color("#2ECC71") } - // let hp_y = this.node.getComponent(UITransform).height+10; - // this.top_node.setPosition(0, hp_y, 0); } @@ -169,12 +168,11 @@ export class HeroViewComp extends CCComp { /** 显示护盾 */ private show_shield(shield: number = 0, shield_max: number = 0) { this.lastBarUpdateTime = Date.now() / 1000; - if(!this.top_node.active) return let shield_progress = shield / shield_max; this.node.getChildByName("shielded").active = shield > 0; this.top_node.getChildByName("shield").active = shield > 0; this.top_node.getChildByName("shield").getComponent(ProgressBar).progress = shield_progress; - + this.setTopBarOpacity(false); } /** 显示血量 */ @@ -201,19 +199,24 @@ export class HeroViewComp extends CCComp { } } - private isFullHp(): boolean { + private isFullHpAndNoShield(): boolean { if (!this.model) return false; if (this.model.hp_max <= 0) return false; - return this.model.hp >= this.model.hp_max; + const isFullHp = this.model.hp >= this.model.hp_max; + const noShield = this.model.shield <= 0; + return isFullHp && noShield; } private setTopBarOpacity(isActive: boolean) { - if (!this.topOpacity || !this.topOpacity.isValid) return; - if (isActive) { + if (!this.top_node || !this.top_node.isValid) return; + if (this.topOpacity) { this.topOpacity.opacity = this.barActiveOpacity; + } + if (isActive) { + this.top_node.active = true; return; } - this.topOpacity.opacity = this.isFullHp() ? this.barIdleOpacity : this.barActiveOpacity; + this.top_node.active = !this.isFullHpAndNoShield(); } private activateTopBar() {