refactor(map): 重构地图动画播放逻辑,修复速度残留问题

1. 给playAnimations方法新增speed参数,支持自定义播放倍率
2. 移除硬编码的4倍速,改用可配置的常量
3. 调用处传入明确speed值,避免上一次加速状态残留
4. 补充方法注释说明参数含义和设计原因
This commit is contained in:
panFD
2026-09-13 11:53:11 +08:00
parent be6af4d157
commit a2f80e45b5
2 changed files with 15 additions and 7 deletions

View File

@@ -49,6 +49,9 @@ import {
} from "../common/config/StageSet";
const { ccclass, property } = _decorator;
/** 节间过场背景滚动速度倍率(强化推进感);大厅/常态滚动为 1x */
const MapLayerScrollSpeed = 4;
/** 任务(关卡)生命周期阶段 */
export enum MissionPhase {
None = 0, // 未初始化
@@ -226,8 +229,8 @@ export class MissionComp extends CCComp {
onDestroy() {
// 解除节间过场移动动画锁,避免泄漏到下一关
MoveSystem.transitionMoveLock = false;
// 退出关卡时恢复地图背景动画
smc.map.MapView.scene.mapLayer.playAnimations()
// 退出关卡时恢复地图背景动画(显式 1x,清除节间过场 4x 残留)
smc.map.MapView.scene.mapLayer.playAnimations(undefined, 1)
super.onDestroy();
if (this.start_btn && this.start_btn.isValid) {
this.start_btn.off(NodeEventType.TOUCH_END, this.onStartFightBtnClick, this);
@@ -1083,8 +1086,8 @@ export class MissionComp extends CCComp {
private beginSectionTransition() {
smc.mission.in_fight = false;
smc.vmdata.mission_data.in_fight = false;
// 恢复地图背景滚动(与英雄归位同步启动,2 倍速表现推进)
smc.map?.MapView?.scene?.mapLayer?.playAnimations();
// 恢复地图背景滚动(与英雄归位同步启动,4 倍速表现推进)
smc.map?.MapView?.scene?.mapLayer?.playAnimations(undefined, MapLayerScrollSpeed);
// 过场期间英雄保持移动动画:即使已归位也持续行军,地图停才回待机
MoveSystem.transitionMoveLock = true;
this.changePhase(MissionPhase.BattleEnd);

View File

@@ -89,14 +89,19 @@ export default class MapLayer extends Component {
/** 背景滚动播放速度倍率(节间过场加快推进感) */
private static readonly SCROLL_SPEED = 4;
public playAnimations(name?: string): void {
/**
* 播放背景滚动动画。
* @param name 动画名(缺省播 defaultClip)
* @param speed 播放速度倍率:大厅/常态=1,节间过场=SCROLL_SPEED。
* 每次 play 都显式覆盖 state.speed,避免上一次 4x 加速残留泄漏到大厅。
*/
public playAnimations(name?: string, speed: number = 1): void {
this.animations.forEach(a => {
a.play(name);
// 加快背景滚动速度,强化节间"向前推进"的观感(AnimationState.speed 属性)
const clip = a.defaultClip;
if (clip) {
const state = a.getState(clip.name);
if (state) state.speed = MapLayer.SCROLL_SPEED;
if (state) state.speed = speed;
}
});
}