StartScene.ts 3.3 KB

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