From 2e24e1fc645805ff2f49ff3fdf87b125257c1a4e Mon Sep 17 00:00:00 2001 From: walkpan Date: Mon, 20 Oct 2025 20:58:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor(map):=20=E4=BC=98=E5=8C=96=E8=8B=B1?= =?UTF-8?q?=E9=9B=84=E8=8A=82=E7=82=B9=E5=B7=A6=E5=8F=B3=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 调整moveHeroesLeft方法,动画开始前销毁第6个英雄节点,避免重复渲染 - 实现英雄节点向左平滑移动,使用Tween过渡动画 - 延迟重排英雄节点数组,确保动画完成后数组正确更新 - 调整moveHeroesRight方法,动画开始前销毁第0个英雄节点,避免重复渲染 - 实现英雄节点向右平滑移动,使用Tween过渡动画 - 延迟重排英雄节点数组,确保动画完成后数组正确更新 - 移除close方法中无用的节点移除逻辑,改用reset方法销毁节点 - 更新prefab中部分控件位置和尺寸,微调界面布局样式 --- assets/resources/gui/role_controller.prefab | 16 +++---- assets/script/game/map/HInfoComp.ts | 53 ++++++++++----------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/assets/resources/gui/role_controller.prefab b/assets/resources/gui/role_controller.prefab index 8402ab40..4a5b2093 100644 --- a/assets/resources/gui/role_controller.prefab +++ b/assets/resources/gui/role_controller.prefab @@ -180,7 +180,7 @@ }, "_lpos": { "__type__": "cc.Vec3", - "x": -300, + "x": -276.526, "y": 1130, "z": 0 }, @@ -230,7 +230,7 @@ }, "_lpos": { "__type__": "cc.Vec3", - "x": 14.894, + "x": 0, "y": -5, "z": 0 }, @@ -369,7 +369,7 @@ }, "_lpos": { "__type__": "cc.Vec3", - "x": -21.369, + "x": -30.654, "y": 0, "z": 0 }, @@ -508,7 +508,7 @@ }, "_lpos": { "__type__": "cc.Vec3", - "x": 40.92, + "x": 24.748, "y": 0, "z": 0 }, @@ -658,8 +658,8 @@ }, "_contentSize": { "__type__": "cc.Size", - "width": 100, - "height": 60 + "width": 150, + "height": 100 }, "_anchorPoint": { "__type__": "cc.Vec2", @@ -758,9 +758,9 @@ }, "_alignFlags": 9, "_target": null, - "_left": 10, + "_left": 8.47399999999999, "_right": 20, - "_top": 120, + "_top": 100, "_bottom": 35, "_horizontalCenter": 0, "_verticalCenter": 0, diff --git a/assets/script/game/map/HInfoComp.ts b/assets/script/game/map/HInfoComp.ts index 93916b69..c90d5eb6 100644 --- a/assets/script/game/map/HInfoComp.ts +++ b/assets/script/game/map/HInfoComp.ts @@ -147,12 +147,18 @@ export class HInfoComp extends Component { this.moveHeroesLeft(); } - moveHeroesRight() { - // 移动所有现有节点向右 - for (let i = 0; i < this.heroNodes.length; i++) { + moveHeroesLeft() { + // 在动画开始前,直接销毁hero_pos[6]上的节点 + if (this.heroNodes[6]) { + this.heroNodes[6].destroy(); + this.heroNodes[6] = null; + } + + // 移动所有现有节点向左(除了已销毁的heroNodes[6]) + for (let i = 0; i < 6; i++) { if (this.heroNodes[i]) { - // 计算目标位置 - let targetPos = this.hero_pos[i + 1] || this.hero_pos[0]; + // 计算目标位置:向左移动 + let targetPos = this.hero_pos[i + 1]; // 使用Tween执行平滑移动 tween(this.heroNodes[i]) @@ -161,14 +167,9 @@ export class HInfoComp extends Component { } } - // 延迟创建新节点和删除旧节点,等待动画完成 + // 延迟重排数组和创建新节点,等待动画完成 setTimeout(() => { - // 删除原先位于hero_pos[6]位置的节点 - if (this.heroNodes[6]) { - this.heroNodes[6].destroy(); - } - - // 移动数组元素 + // 移动数组元素(向后平移) for (let i = 6; i > 0; i--) { this.heroNodes[i] = this.heroNodes[i - 1]; } @@ -187,12 +188,18 @@ export class HInfoComp extends Component { }, 300); // 与动画时间保持一致 } - moveHeroesLeft() { - // 移动所有现有节点向左 - for (let i = 0; i < this.heroNodes.length; i++) { + moveHeroesRight() { + // 在动画开始前,直接销毁hero_pos[0]上的节点 + if (this.heroNodes[0]) { + this.heroNodes[0].destroy(); + this.heroNodes[0] = null; + } + + // 移动所有现有节点向右(除了已销毁的heroNodes[0]) + for (let i = 1; i < this.heroNodes.length; i++) { if (this.heroNodes[i]) { - // 计算目标位置 - let targetPos = this.hero_pos[i - 1] || this.hero_pos[6]; + // 计算目标位置:向右移动 + let targetPos = this.hero_pos[i - 1]; // 使用Tween执行平滑移动 tween(this.heroNodes[i]) @@ -201,14 +208,9 @@ export class HInfoComp extends Component { } } - // 延迟创建新节点和删除旧节点,等待动画完成 + // 延迟重排数组和创建新节点,等待动画完成 setTimeout(() => { - // 删除原先位于hero_pos[0]位置的节点 - if (this.heroNodes[0]) { - this.heroNodes[0].destroy(); - } - - // 移动数组元素 + // 移动数组元素(向前平移) for (let i = 0; i < 6; i++) { this.heroNodes[i] = this.heroNodes[i + 1]; } @@ -227,9 +229,6 @@ export class HInfoComp extends Component { }, 300); // 与动画时间保持一致 } - close(){ - oops.gui.removeByNode(this.node) - } reset() { this.node.destroy() }