StartScene.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. this._logo();
  31. this._btnLogin.on(Button.EventType.CLICK,()=>{
  32. director.loadScene("SelectScene");
  33. })
  34. this._carrot.setScale(0.5,0.5);
  35. this._birdAnimation();
  36. }
  37. private _logo(){
  38. let opacityLogo = this._logoPic.getComponent(UIOpacity);
  39. tween(opacityLogo)
  40. .call(()=>{opacityLogo.opacity = 10;})
  41. .to(2,{opacity:255})
  42. .call(()=>{
  43. this._loading();
  44. opacityLogo.opacity = 0;})
  45. .start();
  46. }
  47. private _loading(){
  48. const setOpacity = (component,targetOpacity) => {
  49. const opacityComponent = component.getComponent(UIOpacity);
  50. tween(opacityComponent)
  51. .call(()=>{opacityComponent.opacity = targetOpacity;})
  52. .start();
  53. }
  54. setOpacity(this._loadingPic,255);
  55. setOpacity(this._progressBar,255);
  56. tween(this._bar)
  57. .call(()=>{this._bar.setScale(0,1)})
  58. .to(2,{scale:new Vec2(2,1)})
  59. .call(()=>{
  60. this._logoNode.active = false;
  61. if(!this._startNode.active){
  62. this._startNode.active = true;
  63. }
  64. })
  65. .start();
  66. }
  67. private _birdAnimation(){
  68. let x = this._bird.getPosition().x;
  69. let y = this._bird.getPosition().y;
  70. tween(this._bird)
  71. .repeatForever(
  72. tween()
  73. .to(1,{position : new Vec3(x,y - 10)},{easing : 'sineInOut'})
  74. .to(1,{position : new Vec3(x,y + 10)},{easing : 'sineInOut'})
  75. )
  76. .start();
  77. }
  78. //节点隐藏的时候调用
  79. // protected onDisable(): void {
  80. // this.getComponentsInChildren(Animation).forEach(ani=>{
  81. // ani.stop();
  82. // });
  83. // }
  84. //节点激活的时候调用
  85. // protected onEnable(): void {
  86. // this.getComponentsInChildren(Animation).forEach(ani=>{
  87. // ani.play();
  88. // })
  89. // }
  90. update(deltaTime: number) {
  91. let x = this._bird.getPosition().x;
  92. let y = this._bird.getPosition().y;
  93. this._bird.setPosition(x,y)
  94. }
  95. }