Login.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const {ccclass, property} = cc._decorator;
  2. /**登录界面 */
  3. @ccclass
  4. export default class Login extends cc.Component {
  5. public btn_start:cc.Node;
  6. public btn_teach:cc.Node;
  7. public progressBar:cc.Sprite;
  8. public onLoad():void{
  9. this.btn_start = this.node.getChildByName('start');
  10. this.btn_teach = this.node.getChildByName('teach');
  11. this.progressBar = this.node.getChildByName('progress').getChildByName('bar').getComponent(cc.Sprite);
  12. this.btn_start.on(cc.Node.EventType.TOUCH_END,this.startGame,this);
  13. this.btn_teach.on(cc.Node.EventType.TOUCH_END,this.startGame.bind(this,true),this,);
  14. this.adapteDevice();
  15. this.fadeInAnimation();
  16. cc.audioEngine.playMusic(window.gameMgr.ad_bgm,true);
  17. }
  18. /**入场动画 */
  19. private fadeInAnimation():void{
  20. this.btn_start.x = window.gameMgr.gameViewSize.width;
  21. this.btn_start.runAction(cc.sequence(
  22. cc.delayTime(0.5),
  23. cc.moveTo(0.5,cc.v2(0,this.btn_start.y)).easing(cc.easeBackOut()),
  24. cc.shake(0.5,20,20),
  25. ));
  26. this.scheduleOnce(()=>{
  27. cc.audioEngine.playEffect(window.gameMgr.ad_bong,false);
  28. },0.8);
  29. }
  30. /**适配设备 */
  31. public adapteDevice():void{
  32. let winWidth = cc.winSize.width;
  33. let winHeight = cc.winSize.height;
  34. let desWidth = cc.view.getDesignResolutionSize().width;
  35. let desHeight = cc.view.getDesignResolutionSize().height;
  36. //fixHeight前提下的适配方案
  37. if(winWidth/winHeight>desWidth/desHeight+0.1){
  38. //如果设备过宽,背景宽度不变(针对ipad)
  39. window.gameMgr.gameViewSize = cc.size(desWidth,desHeight);//记录游戏可视区域大小
  40. }else if(winWidth/winHeight<desWidth/desHeight-0.1){
  41. //如果设备长,背景宽度不变,让背景宽度溢出(针对iphoneX);
  42. window.gameMgr.gameViewSize = cc.size(cc.winSize.width,desHeight);//记录游戏可视区域大小
  43. }else{
  44. //接近设计分辨率的设备则背景宽度拉伸至设备宽度
  45. this.node.width = cc.winSize.width;
  46. window.gameMgr.gameViewSize = cc.winSize;//记录游戏可视区域大小
  47. }
  48. //该节点所有子节点适配游戏可视域
  49. for(let i=0;i<this.node.childrenCount;i++){
  50. let child = this.node.children[i];
  51. child.scaleX *= window.gameMgr.gameViewSize.width/cc.view.getDesignResolutionSize().width;
  52. }
  53. }
  54. /**开始游戏 */
  55. startGame(teach?:boolean):void{
  56. cc.audioEngine.playEffect(window.gameMgr.ad_btn,false);
  57. this.btn_start.destroy();
  58. this.btn_teach.destroy();
  59. this.progressBar.node.parent.active = true;
  60. //开始加载远程资源
  61. cc.loader.loadResDir('',cc.Asset,(completeCount,totalCount)=>{
  62. this.progressBar.fillRange = completeCount/totalCount;
  63. },()=>{
  64. this.node.removeAllChildren(true);
  65. let isOldPlayer = cc.sys.localStorage.getItem('isOldPlayer');
  66. if(isOldPlayer=='true'&&teach!=true){
  67. window.gameMgr.startGame();
  68. }else{
  69. window.gameMgr.startTeachMode();
  70. }
  71. });
  72. }
  73. }