StartScene.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { _decorator, Button, Component, Node,director ,tween, Vec3, Vec2, UIOpacity, Animation,} from 'cc';
  2. import { resMgr } from './Frames/ResourcesMgr';
  3. import { dataMgr } from './Frames/DataManager';
  4. import { UIBase } from './Game/GameFrameWork/UIBase';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('StartScene')
  7. export class StartScene extends UIBase {
  8. private _bird:Node = null;
  9. private _carrot:Node = null;
  10. private _btnLogin: Node = null;
  11. private _progressBar:Node = null;
  12. private _bar:Node = null;
  13. private _logoPic:Node = null;
  14. private _loadingPic:Node = null;
  15. private _startNode: Node = null;
  16. private _logoNode: Node = null;
  17. protected onLoad(): void {
  18. this._startNode = this.node.getChildByName("Start");
  19. this._logoNode = this.node.getChildByName("Logo");
  20. this._bird = this.node.getChildByPath("Start/Bird");
  21. this._carrot = this.node.getChildByPath("Start/Carrot");
  22. this._btnLogin = this.node.getChildByPath("Start/Button");
  23. this._progressBar = this.node.getChildByPath("Logo/ProgressBar");
  24. this._bar = this.node.getChildByPath("Logo/ProgressBar/Bar");
  25. this._logoPic = this.node.getChildByPath("Logo/LogoBg");
  26. this._loadingPic = this.node.getChildByPath("Logo/LoadingBg");
  27. }
  28. async onStart() {
  29. await dataMgr.loadDataDir("Data");
  30. await resMgr.loadAllRes("Res");
  31. await resMgr.loadAllRes("Theme");
  32. this._logo();
  33. this._btnLogin.on(Button.EventType.CLICK,()=>{
  34. director.loadScene("SelectScene");
  35. })
  36. this._carrot.setScale(0.5,0.5);
  37. this._birdAnimation();
  38. }
  39. private _logo(){
  40. let opacityLogo = this._logoPic.getComponent(UIOpacity);
  41. tween(opacityLogo)
  42. .call(()=>{opacityLogo.opacity = 10;})
  43. .to(2,{opacity:255})
  44. .call(()=>{
  45. this._loading();
  46. opacityLogo.opacity = 0;})
  47. .start();
  48. }
  49. private _loading(){
  50. const setOpacity = (component,targetOpacity) => {
  51. const opacityComponent = component.getComponent(UIOpacity);
  52. tween(opacityComponent)
  53. .call(()=>{opacityComponent.opacity = targetOpacity;})
  54. .start();
  55. }
  56. setOpacity(this._loadingPic,255);
  57. setOpacity(this._progressBar,255);
  58. tween(this._bar)
  59. .call(()=>{this._bar.setScale(0,1)})
  60. .to(2,{scale:new Vec2(2,1)})
  61. .call(()=>{
  62. this._logoNode.active = false;
  63. if(!this._startNode.active){
  64. this._startNode.active = true;
  65. }
  66. })
  67. .start();
  68. }
  69. private _birdAnimation(){
  70. let x = this._bird.getPosition().x;
  71. let y = this._bird.getPosition().y;
  72. tween(this._bird)
  73. .repeatForever(
  74. tween()
  75. .to(1,{position : new Vec3(x,y - 10)},{easing : 'sineInOut'})
  76. .to(1,{position : new Vec3(x,y + 10)},{easing : 'sineInOut'})
  77. )
  78. .start();
  79. }
  80. //节点隐藏的时候调用
  81. // protected onDisable(): void {
  82. // this.getComponentsInChildren(Animation).forEach(ani=>{
  83. // ani.stop();
  84. // });
  85. // }
  86. //节点激活的时候调用
  87. // protected onEnable(): void {
  88. // this.getComponentsInChildren(Animation).forEach(ani=>{
  89. // ani.play();
  90. // })
  91. // }
  92. update(deltaTime: number) {
  93. let x = this._bird.getPosition().x;
  94. let y = this._bird.getPosition().y;
  95. this._bird.setPosition(x,y)
  96. }
  97. }