refactor(map): replace main node显隐操作转为动画控制
将原来通过查找main节点手动控制显隐的逻辑,替换为新增的MapLayer动画启停方法,简化代码逻辑并统一动画管理方式
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user