login.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. // Learn cc.Class:
  2. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. loginlayou: cc.Node
  14. },
  15. // LIFE-CYCLE CALLBACKS:
  16. onLoad () {
  17. utils.redytoLoadScene("game");
  18. utils.redytoLoadScene("end");
  19. utils.redytoLoadScene("teaching");
  20. utils.isMobile(function () {
  21. manager_android_js.getNavigator();
  22. }.bind(this));
  23. },
  24. start() {
  25. // if (manager_android_js != null) {
  26. // manager_android_js.loginnameger = this;
  27. // manager_android_js.getNavigator();
  28. //
  29. //
  30. // if (manager_android_js.isiOS == true) {
  31. // manager_android_js.startGame();
  32. // }else{
  33. // this.init();
  34. // }
  35. // }
  36. this.init();
  37. },
  38. initStartGame : function(){
  39. this.init();
  40. },
  41. init: function () {
  42. this._parent = this.loginlayou;
  43. this.loginlayou.active = true;
  44. // this.initLeft(PlayerInfo.Left);
  45. //
  46. // this.readyRight();
  47. // this.startCountDownTime();
  48. // setTimeout(function () {
  49. //
  50. // this.matchingSuccess();
  51. // }.bind(this), 1000)
  52. this.startButton = UtilsNode.getNode("startButton",this.loginlayou)
  53. UtilsNode.setOn(this.startButton,function () {
  54. this.allViewActive(false);
  55. utils.toLoadScene("game")
  56. }.bind(this));
  57. this.gpTeaching = UtilsNode.getNode("gpTeaching",this.loginlayou)
  58. UtilsNode.setOn(this.gpTeaching,function () {
  59. this.allViewActive(false);
  60. utils.toLoadScene("teaching")
  61. }.bind(this));
  62. },
  63. allViewActive(b){
  64. this.startButton.active = b
  65. this.gpTeaching.active = b
  66. },
  67. //匹配成功
  68. matchingSuccess: function () {
  69. // this.initRight(PlayerInfo.Right);
  70. this.stopCountDownTime();
  71. // this.handle();
  72. // manager_android_js.myPlayerInfo = PlayerInfo;
  73. // this.callbackAudioSource = function () {
  74. //
  75. // this.getComponent(cc.AudioSource).volume = 0.5;
  76. // this.getComponent(cc.AudioSource).play();
  77. // }
  78. // this.scheduleOnce(this.callbackAudioSource, 0.05);
  79. //
  80. // this.callbackLoadScene = function () {
  81. // cc.director.loadScene("game");
  82. // }
  83. //
  84. //
  85. // this.scheduleOnce(this.callbackLoadScene, 1);
  86. },
  87. //匹配成功的处理
  88. handle: function () {
  89. this.getNode("Cancel").active = false;
  90. this.getNode("zhao").active = false;
  91. this.getNode("chenggong").active = true;
  92. },
  93. startCountDownTime: function () {
  94. this.timeData = {
  95. branch: "00",
  96. second: "00"
  97. }
  98. this.waittime = this.getNode("waittime");
  99. this.waittime.getComponent(cc.Label).string = this.timeData.branch + ":" + this.timeData.second
  100. this.time_count = 0;
  101. this.time_branch = 0;
  102. this.time_second = 10;
  103. this.callbackCountDownTime = function () {
  104. this.time_second++;
  105. if (this.time_second > 60) {
  106. this.time_second = 0;
  107. this.time_branch++;
  108. }
  109. this.time_count++;
  110. //设置秒
  111. var second;
  112. if (this.time_second < 10) {
  113. second = '0' + this.time_second;
  114. } else {
  115. second = this.time_second;
  116. }
  117. this.timeData.second = second + "";
  118. var branch;
  119. if (this.time_branch < 10) {
  120. branch = '0' + this.time_branch;
  121. } else {
  122. branch = this.time_branch;
  123. }
  124. this.timeData.branch = branch + "";
  125. // console.log("我们的时间", this.timeData);
  126. this.updetaTime(this.timeData);
  127. }
  128. this.schedule(this.callbackCountDownTime, 1);
  129. },
  130. updetaTime: function (timeData) {
  131. this.waittime.getComponent(cc.Label).string = timeData.branch + ":" + timeData.second
  132. },
  133. //停止倒计时
  134. stopCountDownTime: function () {
  135. this.unschedule(this.callbackCountDownTime);
  136. },
  137. initLeft: function (data) {
  138. var temp;
  139. if (data == null) {
  140. temp = {
  141. id: 9527,
  142. name: "汪汪husky",
  143. gender: 0,
  144. head: "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=857896439,118415596&fm=27&gp=0.jpg"
  145. // head: "https://www.yuyekeji.cn/media/user/Images/Share.png"
  146. }
  147. } else {
  148. temp = data;
  149. }
  150. // temp
  151. var parent = this.getNode("AvatarMale");
  152. var playname = this.getNode("playname", parent);
  153. var Male = this.getNode("Male", parent);
  154. var Female = this.getNode("Female", parent);
  155. var mask = this.getNode("mymask", parent);
  156. var head = mask.getChildByName("head");
  157. if (temp.gender == 0) {
  158. Male.active = true;
  159. Female.active = false;
  160. } else {
  161. Male.active = false;
  162. Female.active = true;
  163. }
  164. playname.getComponent(cc.Label).string = temp.name;
  165. this.loadImg(head, temp.head, 150, 150)
  166. },
  167. initRight: function (data) {
  168. var temp;
  169. if (data == null) {
  170. temp = {
  171. id: 9528,
  172. name: "妹妹husky",
  173. gender: 1,
  174. head: ""
  175. }
  176. } else {
  177. temp = data;
  178. }
  179. // temp
  180. var parent = this.getNode("AvatarFemale");
  181. var playname = this.getNode("playname", parent);
  182. var Male = this.getNode("Male", parent);
  183. var Female = this.getNode("Female", parent);
  184. var mask = this.getNode("mymask", parent);
  185. var head = mask.getChildByName("head");
  186. parent.active = true;
  187. if (temp.gender == 0) {
  188. Male.active = true;
  189. Female.active = false;
  190. } else {
  191. Male.active = false;
  192. Female.active = true;
  193. }
  194. playname.getComponent(cc.Label).string = temp.name
  195. this.loadImg(head, temp.head, 150, 150)
  196. },
  197. readyRight: function () {
  198. var parent = this.getNode("PinkFrameFillColor");
  199. var left = this.getNode("left", parent);
  200. var middle = this.getNode("middle", parent);
  201. var right = this.getNode("right", parent);
  202. var left_Position = left.getPosition();
  203. var middle_Position = middle.getPosition();
  204. var right_Position = right.getPosition();
  205. // var arrp = [];
  206. // arrp.push(left_Position);
  207. // arrp.push(middle_Position);
  208. // arrp.push(right_Position);
  209. var arrp = [];
  210. arrp.push(right_Position);
  211. arrp.push(middle_Position);
  212. arrp.push(left_Position);
  213. var arrn = [];
  214. arrn.push(left);
  215. arrn.push(middle);
  216. arrn.push(right);
  217. this.count = 0;
  218. this.callback = function () {
  219. var temp = arrp[arrp.length - 1];
  220. arrp.unshift(temp);
  221. arrp.pop()
  222. // console.log("操作",arrn);
  223. if (this.count == arrp.length) {
  224. // 在第六次执行回调时取消这个计时器
  225. // this.unschedule(this.callback);
  226. this.count = 0;
  227. }
  228. for (var i = 0; i < arrp.length; i++) {
  229. arrn[i].x = arrp[i].x;
  230. }
  231. this.count++;
  232. }
  233. this.schedule(this.callback, 0.5);
  234. },
  235. getNode: function (name, parent) {
  236. if (parent == null) {
  237. return this._parent.getChildByName(name);
  238. } else {
  239. return parent.getChildByName(name);
  240. }
  241. },
  242. //取消匹配
  243. cancelmatch: function () {
  244. console.log("取消匹配");
  245. },
  246. loadImg: function (container, url, w, h) {
  247. var newurl = utils.getNewHttpImage(url);
  248. cc.loader.load(newurl,function (err, texture) {
  249. var sprite = new cc.SpriteFrame(texture);
  250. container.getComponent(cc.Sprite).spriteFrame = sprite;
  251. if (w != null) {
  252. container.width = w;
  253. }
  254. if (h != null) {
  255. container.height = h;
  256. }
  257. });
  258. },
  259. // update (dt) {},
  260. });