feat(hero): 添加英雄合并时的移动动画效果

实现英雄合并时的平滑移动动画,避免直接销毁的突兀感。为 Hero 类新增 mergeToBirthAndDestroy 方法,使英雄在销毁前移动到生成点。在 MissionHeroComp 中,合并逻辑改为异步等待动画完成,并添加防重复合并标志。
This commit is contained in:
panw
2026-03-27 14:33:00 +08:00
parent 1919c10497
commit 6fe91e0104
2 changed files with 67 additions and 12 deletions

View File

@@ -151,6 +151,33 @@ export class Hero extends ecs.Entity {
})
.start();
}
mergeToBirthAndDestroy(birthPos: Vec3, onDone?: () => void) {
const view = this.get(HeroViewComp);
const node = view?.node;
if (!node || !node.isValid) {
this.destroy();
if (onDone) onDone();
return;
}
const collider = node.getComponent(BoxCollider2D);
if (collider) {
collider.enabled = false;
collider.apply();
}
const currentPos = node.getPosition();
const targetPos = v3(birthPos.x, birthPos.y, 0);
const moveDistance = Vec3.distance(currentPos, targetPos);
const moveDuration = Math.max(0.12, Math.min(0.3, moveDistance / 1200));
Tween.stopAllByTarget(node);
tween(node)
.to(moveDuration, { position: targetPos })
.call(() => {
this.destroy();
if (onDone) onDone();
})
.start();
}
/** 重置入口:复用 destroy 的释放流程 */
reset() {