From 4670b123307e4ef8cee274905abf2c59825f2929 Mon Sep 17 00:00:00 2001 From: walkpan Date: Mon, 3 Nov 2025 23:40:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=8B=B1=E9=9B=84=E8=A7=86=E5=9B=BE):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A1=80=E6=9D=A1=E6=98=BE=E7=A4=BA=E8=AE=A1?= =?UTF-8?q?=E6=97=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增血条显示持续时间配置和计时器,修改血条显示逻辑: 1. 添加 hpBarShowTime 和 hpBarShowCD 字段控制血条显示时间 2. 初始隐藏血条,仅在受到攻击时显示并开始计时 3. 移除满血自动隐藏逻辑,改为仅更新进度条 4. 重置状态时清除血条计时器 --- assets/script/game/hero/HeroViewComp.ts | 31 +++++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index 8a066392..534ff710 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -34,6 +34,9 @@ export class HeroViewComp extends CCComp { useMp:boolean = false; realDeadTime:number=10 deadCD:number=0 + // 血条显示相关 + hpBarShowTime:number = 5; // 血条显示持续时间(秒) + hpBarShowCD:number = 0; // 血条显示计时器 // ==================== UI 节点引用 ==================== private top_node: Node = null!; @@ -89,6 +92,8 @@ export class HeroViewComp extends CCComp { this.useMp=HeroInfo[this.model.hero_uuid].type==HType.mage||HeroInfo[this.model.hero_uuid].type==HType.remote||HeroInfo[this.model.hero_uuid].type==HType.support; this.top_node.getChildByName("pow").active = this.usePower; this.top_node.getChildByName("mp").active = this.useMp; + // 初始隐藏血条(被攻击后才显示) + this.top_node.active = false; } /** 初始化 UI 节点引用 */ @@ -119,6 +124,17 @@ export class HeroViewComp extends CCComp { } return } ; + + // 处理血条显示计时 + if (this.hpBarShowCD > 0) { + this.hpBarShowCD -= dt; + if (this.hpBarShowCD <= 0) { + // 时间到,隐藏血条 + this.top_node.active = false; + this.hpBarShowCD = 0; + } + } + // ✅ View 层职责:处理表现相关的逻辑 this.processDamageQueue(); // 伤害数字显示队列 @@ -144,11 +160,9 @@ export class HeroViewComp extends CCComp { /** 显示血量 */ private hp_show(hp: number, hp_max: number) { - if(hp==hp_max) { - this.top_node.active=false; - return - } - this.top_node.active=true + // 不再基于血量是否满来决定显示状态,只更新进度条 + if(!this.top_node.active) return; + let hp_progress = hp / hp_max; this.top_node.getChildByName("hp").getComponent(ProgressBar).progress = hp_progress; this.scheduleOnce(() => { @@ -292,6 +306,7 @@ export class HeroViewComp extends CCComp { this.status_change("idle"); this.model.hp =this.model.Attrs[Attrs.HP_MAX]*50/100; this.top_node.active=false + this.hpBarShowCD=0 } /** @@ -334,7 +349,12 @@ export class HeroViewComp extends CCComp { } do_atked(damage:number,isCrit:boolean,s_uuid:number){ + // 受到攻击时显示血条,并设置显示时间(即使伤害为0也显示) + this.top_node.active = true; + this.hpBarShowCD = this.hpBarShowTime; + if (damage <= 0) return; + // 视图层表现 let SConf=SkillSet[s_uuid] this.back() @@ -448,6 +468,7 @@ export class HeroViewComp extends CCComp { collider.off(Contact2DType.BEGIN_CONTACT); } this.deadCD=0 + this.hpBarShowCD=0 // 清理伤害队列 this.damageQueue.length = 0;