| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- var mogobe = require("../Mgobe")
- cc.Class({
- extends: cc.Component,
- properties: {
-
- animationBg: {
- default: null,
- type:cc.Node,
- },
- player1: {
- default: null,
- type:cc.Node,
- },
- player2: {
- default: null,
- type:cc.Node,
- },
- player3: {
- default: null,
- type:cc.Node,
- },
- player4: {
- default: null,
- type:cc.Node,
- },
- titleTxt: {
- default: null,
- type:cc.Node,
- },
- timeTxt: {
- default: null,
- type:cc.Node,
- },
- waitTxt: {
- default: null,
- type:cc.Node,
- },
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad() {
- this.init();
- return cc.loader.loadRes("/cacert", cc.Asset, (err, asset) =>
- {
- console.log("加载证书结束 " + (!err));
- if (err) {
- return;
- }
- mogobe.cacertNativeUrl = asset.nativeUrl;
- mogobe.initSDK(function () {
- mogobe.matchPlayers();
- }.bind(this));
- });
- // mogobe.initSDK();
- // mogobe.matchPlayers(1);
-
- // webView.init(function () {
- // this.initPlayer1();
- // }.bind(this));
- let interval = 1; // 以秒为单位的时间间隔let
- let repeat = cc.macro.REPEAT_FOREVER; // 重复次数
- let delay = 0; // 开始延时
- this.countTime = this.schedule(function()
- {
- this.timeTxt.getComponent(cc.Label).string = this.updateTime(this.matchTime);
- this.matchTime++;
- if (this.matchTime>15)
- {
- this.unschedule(this.countTime);
- this.titleTxt.getComponent(cc.Label).string = "匹配成功";
- this.timeTxt.active = false;
- this.waitTxt.active = false;
- if (this.nowPlayerNum<4){
- //Test//
- // webView.getAiInfo(function () {
- // this.resetUIByData({ webView.rivalAvatarUrl,
- // webView.rivalUserName,
- // webView.rivalGender,});
- // }.bind(this));
- }
- }
- }.bind(this), interval, repeat, delay);
- },
- init () {
- this.matchTime = 0;
- this.nowPlayerNum = 1;
- this.name1 = this.player1.getChildByName('Name');
- this.gender1 = this.player1.getChildByName('Gender');
- this.avatarSp1 = this.player1.getChildByName('Mask').getChildByName('AvatarSp');
- },
- setGender(gender,bBoy)
- {
- this.iconBoy = gender.getChildByName('IconBoy');
- this.iconGirl = gender.getChildByName('IconGirl');
- if(bBoy)
- {
- this.iconBoy.active = true;
- this.iconGirl.active = false;
- }
- else
- {
- this.iconBoy.active = false;
- this.iconGirl.active = true;
- }
- },
- initPlayer1() {
- this.name1.getComponent(cc.Label).string = webView.userName;
- this.setGender(this.gender1,webView.gender);
- cc.loader.load(webView.avatarUrl, function (err, texture)
- {
- let frame = new cc.SpriteFrame(texture);
- if (err) {
- console.log('头像:', err);
- }
- this.avatarSp1.getComponent(cc.Sprite).spriteFrame = frame;
- }.bind(this));
- },
- updateTime(t) {
- let theTime = Math.floor(t);
- let theTime1 = 0;// 分
- if (theTime > 60)
- {
- theTime1 = parseInt(theTime / 60);
- theTime = parseInt(theTime % 60);
- }
- let result = '';
-
- result = (theTime1 < 10 ? "0" + theTime1 : theTime1) + ":" + (theTime < 10 ? "0" + theTime : theTime);
- return result;
- },
- initOtherPlayer(data)
- {
- if(!data) return;
- this.nowPlayerNum++;
-
- let player = this["player"+this.nowPlayerNum];
- let name = player.getChildByName('Name');
- let gender = player.getChildByName('Gender');
- let avatarSp = player.getChildByName('Mask').getChildByName('AvatarSp');
- player.getChildByName("DotAnimation").active = false;
- name.getComponent(cc.Label).string = data.userName;
- this.setGender(gender,data.gender);
- cc.loader.load(data.avatarUrl, function (err, texture)
- {
- let frame = new cc.SpriteFrame(texture);
- if (err) {
- console.log('头像:', err);
- }
- avatarSp.getComponent(cc.Sprite).spriteFrame = frame;
- if (this.nowPlayerNum==4){
- this.scheduleOnce(()=>
- {
- cc.director.loadScene("Game");
- }, 4)
- }
-
- }.bind(this));
- },
- });
|