MutipleMatchingMode.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. var mogobe = require("../Mgobe")
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. animationBg: {
  6. default: null,
  7. type:cc.Node,
  8. },
  9. player1: {
  10. default: null,
  11. type:cc.Node,
  12. },
  13. player2: {
  14. default: null,
  15. type:cc.Node,
  16. },
  17. player3: {
  18. default: null,
  19. type:cc.Node,
  20. },
  21. player4: {
  22. default: null,
  23. type:cc.Node,
  24. },
  25. titleTxt: {
  26. default: null,
  27. type:cc.Node,
  28. },
  29. timeTxt: {
  30. default: null,
  31. type:cc.Node,
  32. },
  33. waitTxt: {
  34. default: null,
  35. type:cc.Node,
  36. },
  37. },
  38. // LIFE-CYCLE CALLBACKS:
  39. onLoad() {
  40. this.init();
  41. return cc.loader.loadRes("/cacert", cc.Asset, (err, asset) =>
  42. {
  43. console.log("加载证书结束 " + (!err));
  44. if (err) {
  45. return;
  46. }
  47. mogobe.cacertNativeUrl = asset.nativeUrl;
  48. mogobe.initSDK(function () {
  49. mogobe.matchPlayers();
  50. }.bind(this));
  51. });
  52. // mogobe.initSDK();
  53. // mogobe.matchPlayers(1);
  54. // webView.init(function () {
  55. // this.initPlayer1();
  56. // }.bind(this));
  57. let interval = 1;  // 以秒为单位的时间间隔let
  58. let repeat = cc.macro.REPEAT_FOREVER;  // 重复次数
  59. let delay = 0;  // 开始延时
  60. this.countTime = this.schedule(function()
  61. {
  62. this.timeTxt.getComponent(cc.Label).string = this.updateTime(this.matchTime);
  63. this.matchTime++;
  64. if (this.matchTime>15)
  65. {
  66. this.unschedule(this.countTime);
  67. this.titleTxt.getComponent(cc.Label).string = "匹配成功";
  68. this.timeTxt.active = false;
  69. this.waitTxt.active = false;
  70. if (this.nowPlayerNum<4){
  71. //Test//
  72. // webView.getAiInfo(function () {
  73. // this.resetUIByData({ webView.rivalAvatarUrl,
  74. // webView.rivalUserName,
  75. // webView.rivalGender,});
  76. // }.bind(this));
  77. }
  78. }
  79. }.bind(this), interval, repeat, delay);
  80. },
  81. init () {
  82. this.matchTime = 0;
  83. this.nowPlayerNum = 1;
  84. this.name1 = this.player1.getChildByName('Name');
  85. this.gender1 = this.player1.getChildByName('Gender');
  86. this.avatarSp1 = this.player1.getChildByName('Mask').getChildByName('AvatarSp');
  87. },
  88. setGender(gender,bBoy)
  89. {
  90. this.iconBoy = gender.getChildByName('IconBoy');
  91. this.iconGirl = gender.getChildByName('IconGirl');
  92. if(bBoy)
  93. {
  94. this.iconBoy.active = true;
  95. this.iconGirl.active = false;
  96. }
  97. else
  98. {
  99. this.iconBoy.active = false;
  100. this.iconGirl.active = true;
  101. }
  102. },
  103. initPlayer1() {
  104. this.name1.getComponent(cc.Label).string = webView.userName;
  105. this.setGender(this.gender1,webView.gender);
  106. cc.loader.load(webView.avatarUrl, function (err, texture)
  107. {
  108. let frame = new cc.SpriteFrame(texture);
  109. if (err) {
  110. console.log('头像:', err);
  111. }
  112. this.avatarSp1.getComponent(cc.Sprite).spriteFrame = frame;
  113. }.bind(this));
  114. },
  115. updateTime(t) {
  116. let theTime = Math.floor(t);
  117. let theTime1 = 0;// 分
  118. if (theTime > 60)
  119. {
  120. theTime1 = parseInt(theTime / 60);
  121. theTime = parseInt(theTime % 60);
  122. }
  123. let result = '';
  124. result = (theTime1 < 10 ? "0" + theTime1 : theTime1) + ":" + (theTime < 10 ? "0" + theTime : theTime);
  125. return result;
  126. },
  127. initOtherPlayer(data)
  128. {
  129. if(!data) return;
  130. this.nowPlayerNum++;
  131. let player = this["player"+this.nowPlayerNum];
  132. let name = player.getChildByName('Name');
  133. let gender = player.getChildByName('Gender');
  134. let avatarSp = player.getChildByName('Mask').getChildByName('AvatarSp');
  135. player.getChildByName("DotAnimation").active = false;
  136. name.getComponent(cc.Label).string = data.userName;
  137. this.setGender(gender,data.gender);
  138. cc.loader.load(data.avatarUrl, function (err, texture)
  139. {
  140. let frame = new cc.SpriteFrame(texture);
  141. if (err) {
  142. console.log('头像:', err);
  143. }
  144. avatarSp.getComponent(cc.Sprite).spriteFrame = frame;
  145. if (this.nowPlayerNum==4){
  146. this.scheduleOnce(()=>
  147. {
  148. cc.director.loadScene("Game");
  149. }, 4)
  150. }
  151. }.bind(this));
  152. },
  153. });