StartScene.ts 3.6 KB

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