| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- const {ccclass, property} = cc._decorator;
- /**登录界面 */
- @ccclass
- export default class Login extends cc.Component {
- public btn_start:cc.Node;
- public btn_teach:cc.Node;
- public progressBar:cc.Sprite;
- public onLoad():void{
- this.btn_start = this.node.getChildByName('start');
- this.btn_teach = this.node.getChildByName('teach');
- this.progressBar = this.node.getChildByName('progress').getChildByName('bar').getComponent(cc.Sprite);
- this.btn_start.on(cc.Node.EventType.TOUCH_END,this.startGame,this);
- this.btn_teach.on(cc.Node.EventType.TOUCH_END,this.startGame.bind(this,true),this,);
- this.adapteDevice();
- this.fadeInAnimation();
- cc.audioEngine.playMusic(window.gameMgr.ad_bgm,true);
- }
- /**入场动画 */
- private fadeInAnimation():void{
- this.btn_start.x = window.gameMgr.gameViewSize.width;
- this.btn_start.runAction(cc.sequence(
- cc.delayTime(0.5),
- cc.moveTo(0.5,cc.v2(0,this.btn_start.y)).easing(cc.easeBackOut()),
- cc.shake(0.5,20,20),
- ));
- this.scheduleOnce(()=>{
- cc.audioEngine.playEffect(window.gameMgr.ad_bong,false);
- },0.8);
- }
- /**适配设备 */
- public adapteDevice():void{
- let winWidth = cc.winSize.width;
- let winHeight = cc.winSize.height;
- let desWidth = cc.view.getDesignResolutionSize().width;
- let desHeight = cc.view.getDesignResolutionSize().height;
- //fixHeight前提下的适配方案
- if(winWidth/winHeight>desWidth/desHeight+0.1){
- //如果设备过宽,背景宽度不变(针对ipad)
- window.gameMgr.gameViewSize = cc.size(desWidth,desHeight);//记录游戏可视区域大小
- }else if(winWidth/winHeight<desWidth/desHeight-0.1){
- //如果设备长,背景宽度不变,让背景宽度溢出(针对iphoneX);
- window.gameMgr.gameViewSize = cc.size(cc.winSize.width,desHeight);//记录游戏可视区域大小
- }else{
- //接近设计分辨率的设备则背景宽度拉伸至设备宽度
- this.node.width = cc.winSize.width;
- window.gameMgr.gameViewSize = cc.winSize;//记录游戏可视区域大小
- }
- //该节点所有子节点适配游戏可视域
- for(let i=0;i<this.node.childrenCount;i++){
- let child = this.node.children[i];
- child.scaleX *= window.gameMgr.gameViewSize.width/cc.view.getDesignResolutionSize().width;
- }
- }
- /**开始游戏 */
- startGame(teach?:boolean):void{
- cc.audioEngine.playEffect(window.gameMgr.ad_btn,false);
- this.btn_start.destroy();
- this.btn_teach.destroy();
- this.progressBar.node.parent.active = true;
- //开始加载远程资源
- cc.loader.loadResDir('',cc.Asset,(completeCount,totalCount)=>{
- this.progressBar.fillRange = completeCount/totalCount;
- },()=>{
- this.node.removeAllChildren(true);
- let isOldPlayer = cc.sys.localStorage.getItem('isOldPlayer');
- if(isOldPlayer=='true'&&teach!=true){
- window.gameMgr.startGame();
- }else{
- window.gameMgr.startTeachMode();
- }
- });
- }
- }
|