StartScene.ts 3.4 KB

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