From 72b31037f5323d7ad0b3db8d999ab12ab84bebf4 Mon Sep 17 00:00:00 2001 From: walkpan Date: Wed, 8 Apr 2026 08:48:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9C=B0=E5=9B=BE):=20=E5=8F=8D=E8=BD=AC?= =?UTF-8?q?=E8=8B=B1=E9=9B=84=E5=8D=A1=E7=89=8C=E6=8E=92=E5=BA=8F=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BB=A5=E5=8C=B9=E9=85=8D=E6=B8=B2=E6=9F=93=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 由于 cc.Layout 的节点渲染顺序与之前手动排序逻辑相反,导致英雄卡牌位置错乱。现在将排序规则改为 x 坐标越小(越靠后排)的 index 越小,并移除手动位置计算,完全依赖 Layout 自动排版。 --- assets/script/game/map/MissionCardComp.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/assets/script/game/map/MissionCardComp.ts b/assets/script/game/map/MissionCardComp.ts index 655826b6..208f1577 100644 --- a/assets/script/game/map/MissionCardComp.ts +++ b/assets/script/game/map/MissionCardComp.ts @@ -841,12 +841,11 @@ export class MissionCardComp extends CCComp { const bView = bEnt?.get(HeroViewComp); const aMove = aEnt?.get(MoveComp); const bMove = bEnt?.get(MoveComp); - // 排序逻辑: - // 1. 如果有 x 坐标,按照 x 坐标从大到小(在前面)排序 - // 2. 如果没有 x 坐标,默认退化到按照生成顺序或 eid 排序 + // 排序逻辑反转:适应 cc.Layout 的节点渲染顺序(先渲染/index小的在左边) + // 1. x 坐标越小(越靠后排)的,index 应该越小 const aFrontScore = aView?.node?.position?.x ?? -999999; const bFrontScore = bView?.node?.position?.x ?? -999999; - if (aFrontScore !== bFrontScore) return bFrontScore - aFrontScore; + if (aFrontScore !== bFrontScore) return aFrontScore - bFrontScore; const aSpawnOrder = aMove?.spawnOrder ?? 0; const bSpawnOrder = bMove?.spawnOrder ?? 0; @@ -861,11 +860,8 @@ export class MissionCardComp extends CCComp { const item = sortedItems[index]; if (!item.node || !item.node.isValid) continue; - // 使用 Widget 布局的话需要禁用它或者单纯调整位置 - // 这里我们使用绝对坐标进行排列,假设是从左到右 - const targetX = index * (this.heroInfoItemGap + this.heroInfoItemSpacing); - const pos = item.node.position; - item.node.setPosition(targetX, pos.y, pos.z); + // 既然使用了 cc.Layout 进行自动排版,我们只需设置渲染顺序 + // Layout 会自动根据 siblingIndex 对所有子节点重新排位 item.node.setSiblingIndex(index); } }