refactor(map): 将任务卡面板隐藏动画由位置移动改为缩放

将战斗阶段卡牌面板的隐藏方式从向下移动改为缩放至零,简化动画逻辑并避免因父节点缩放导致的偏移计算问题。移除不再使用的 cardsBattleHideOffsetY 属性,并缓存卡牌面板的原始缩放比例。
This commit is contained in:
panw
2026-03-27 09:10:57 +08:00
parent 4e7c580936
commit 0b20d773d2
2 changed files with 3106 additions and 3083 deletions

View File

@@ -25,8 +25,6 @@ export class MissionCardComp extends CCComp {
/** 四个插卡槽位固定顺序分发1~4 */
@property(Node)
cards_node:Node = null!
@property({ tooltip: "战斗阶段卡牌面板下移隐藏距离" })
cardsBattleHideOffsetY: number = 1280;
@property({ tooltip: "卡牌面板位移动画时长" })
cardsPanelMoveDuration: number = 0.2;
@property(Node)
@@ -59,8 +57,10 @@ export class MissionCardComp extends CCComp {
private poolLv: number = CARD_POOL_INIT_LEVEL;
private readonly heroInfoItemGap: number = 86;
private heroInfoSyncTimer: number = 0;
private cardsShowPos: Vec3 = new Vec3();
private cardsHidePos: Vec3 = new Vec3();
private hasCachedCardsBaseScale: boolean = false;
private cardsBaseScale: Vec3 = new Vec3(1, 1, 1);
private cardsShowScale: Vec3 = new Vec3(1, 1, 1);
private cardsHideScale: Vec3 = new Vec3(0, 0, 1);
private heroInfoItems: Map<number, {
node: Node,
model: HeroAttrsComp,
@@ -296,11 +296,13 @@ export class MissionCardComp extends CCComp {
private initCardsPanelPos() {
if (!this.cards_node || !this.cards_node.isValid) return;
const pos = this.cards_node.position;
const parentScaleY = Math.max(0.001, Math.abs(this.cards_node.parent?.scale?.y ?? 1));
const localOffsetY = Math.abs(this.cardsBattleHideOffsetY) / parentScaleY;
this.cardsShowPos = new Vec3(pos.x, pos.y, pos.z);
this.cardsHidePos = new Vec3(pos.x, pos.y - localOffsetY, pos.z);
if (!this.hasCachedCardsBaseScale) {
const scale = this.cards_node.scale;
this.cardsBaseScale = new Vec3(scale.x, scale.y, scale.z);
this.hasCachedCardsBaseScale = true;
}
this.cardsShowScale = new Vec3(this.cardsBaseScale.x, this.cardsBaseScale.y, this.cardsBaseScale.z);
this.cardsHideScale = new Vec3(0, 0, this.cardsBaseScale.z);
}
private enterPreparePhase() {
@@ -308,7 +310,7 @@ export class MissionCardComp extends CCComp {
this.initCardsPanelPos();
this.cards_node.active = true;
Tween.stopAllByTarget(this.cards_node);
this.cards_node.setPosition(this.cardsShowPos);
this.cards_node.setScale(this.cardsShowScale);
}
private enterBattlePhase() {
@@ -316,9 +318,10 @@ export class MissionCardComp extends CCComp {
this.initCardsPanelPos();
this.cards_node.active = true;
Tween.stopAllByTarget(this.cards_node);
this.cards_node.setScale(this.cardsShowScale);
tween(this.cards_node)
.to(this.cardsPanelMoveDuration, {
position: this.cardsHidePos
scale: this.cardsHideScale
})
.start();
}