From 669aaf1ab937c30fb3c59f05f0fb30695bdef408 Mon Sep 17 00:00:00 2001 From: walkpan Date: Wed, 13 May 2026 23:37:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor(map):=20replace=20main=20node=E6=98=BE?= =?UTF-8?q?=E9=9A=90=E6=93=8D=E4=BD=9C=E8=BD=AC=E4=B8=BA=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将原来通过查找main节点手动控制显隐的逻辑,替换为新增的MapLayer动画启停方法,简化代码逻辑并统一动画管理方式 --- assets/script/game/map/MissionHomeComp.ts | 13 +++--------- .../game/map/view/map/layer/MapLayer.ts | 21 ++++++++++++++++++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/assets/script/game/map/MissionHomeComp.ts b/assets/script/game/map/MissionHomeComp.ts index 3f13a6aa..6ba09bfb 100644 --- a/assets/script/game/map/MissionHomeComp.ts +++ b/assets/script/game/map/MissionHomeComp.ts @@ -80,10 +80,8 @@ export class MissionHomeComp extends CCComp { this.node.active=false; // 隐藏 mapLayer 下的 main 节点 - let mainNode = smc.map.MapView.scene.mapLayer?.node.getChildByName("main"); - if (mainNode) { - mainNode.active = false; - } + smc.map.MapView.scene.mapLayer?.stopAnimations(); + } /** 打开排行榜弹窗 */ @@ -106,12 +104,7 @@ export class MissionHomeComp extends CCComp { home_active(){ this.uodate_data() this.node.active=true - - // 重新显示 mapLayer 下的 main 节点 - let mainNode = smc.map.MapView.scene.mapLayer?.node.getChildByName("main"); - if (mainNode) { - mainNode.active = true; - } + smc.map.MapView.scene.mapLayer?.playAnimations(); } /** 更新主页显示数据(预留) */ diff --git a/assets/script/game/map/view/map/layer/MapLayer.ts b/assets/script/game/map/view/map/layer/MapLayer.ts index 51f21662..ab06b0d2 100644 --- a/assets/script/game/map/view/map/layer/MapLayer.ts +++ b/assets/script/game/map/view/map/layer/MapLayer.ts @@ -18,7 +18,7 @@ * * @author 落日故人 QQ 583051842 */ -import { Component, Layers, Node, Sprite, SpriteFrame, Texture2D, UITransform, Vec3, _decorator } from 'cc'; +import { Animation, Component, Layers, Node, Sprite, SpriteFrame, Texture2D, UITransform, Vec3, _decorator } from 'cc'; import { oops } from '../../../../../../../extensions/oops-plugin-framework/assets/core/Oops'; import { LayerUtil } from '../../../../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil'; import { smc } from '../../../../common/SingletonModuleComp'; @@ -80,6 +80,25 @@ export default class MapLayer extends Component { if (this.bgImg) { return this.bgImg.getComponent(UITransform)!.height; } + } + private get animations(): Animation[] { + return [this.bg_anm, this.bg_anm1, this.bg_anm2, this.bg_anm3, this.bg_anm4].filter((a): a is Animation => a !== null); + } + + public playAnimations(name?: string): void { + this.animations.forEach(a => name ? a.play(name) : a.play()); + } + + public stopAnimations(): void { + this.animations.forEach(a => a.stop()); + } + + public pauseAnimations(): void { + this.animations.forEach(a => a.pause()); + } + + public resumeAnimations(): void { + this.animations.forEach(a => a.resume()); } } \ No newline at end of file