MainHome.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { EventType, ObserverManager } from '../Manager/core/EventManager';
  2. import PrefabManager from '../Manager/core/PrefabManager';
  3. import { UIID } from '../Manager/core/UIID';
  4. import CCUtils from '../Utiles/CCUtils';
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class MainHome extends cc.Component {
  8. /** 头部导航栏 */
  9. private headNode: cc.Node = null;
  10. /** 底部栏 */
  11. private bottomNode: cc.Node = null;
  12. /** selectPrefab */
  13. private selectPrefab: cc.Node = null;
  14. private storeBtn: cc.Node = null;
  15. start() {}
  16. protected onLoad(): void {}
  17. /**
  18. * 初始化
  19. *
  20. * @protected
  21. * @memberof Main
  22. */
  23. protected onEnable(): void {
  24. this.initComponent();
  25. // 加载选择歌曲界面
  26. PrefabManager.open(UIID.SongSelector, this.node, (node: cc.Node) => {
  27. this.selectPrefab = node;
  28. this.setZindex();
  29. });
  30. this.setAdaptation();
  31. }
  32. protected onDisable(): void {
  33. ObserverManager.removeObserver(EventType.OpenGame);
  34. }
  35. /**
  36. * 初始化组件
  37. *
  38. * @private
  39. * @memberof MainHome
  40. */
  41. private initComponent(): void {
  42. this.headNode = CCUtils.findChild(this.node, 'headLayer');
  43. this.bottomNode = CCUtils.findChild(this.node, 'bottomLayer');
  44. this.storeBtn = CCUtils.findChild(this.bottomNode, 'storeBtn');
  45. var seq = cc.repeatForever(
  46. cc.sequence(
  47. cc.scaleTo(1, 0.9),
  48. cc.scaleTo(1, 1.0),
  49. cc.jumpBy(1.0, cc.v2(0, 0), 20, 1)
  50. )
  51. );
  52. this.storeBtn.runAction(seq);
  53. }
  54. private setZindex(): void {
  55. this.headNode.zIndex = 1;
  56. this.bottomNode.zIndex = 1;
  57. this.selectPrefab.zIndex = 0;
  58. }
  59. /**
  60. * 适配
  61. *
  62. * @private
  63. * @memberof SongSelector
  64. */
  65. private setAdaptation(): void {
  66. // 设置适配
  67. const height: number = this.node.parent.height;
  68. console.log('===height===', height);
  69. this.headNode.y = height / 2;
  70. }
  71. }