sharelayoutManager.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // ShareTexts:null,
  14. StarImgs: [cc.SpriteFrame],
  15. },
  16. // LIFE-CYCLE CALLBACKS:
  17. // onLoad () {},
  18. start() {
  19. this.ShareTexts=[
  20. //月球0
  21. "送ta上去月球表面流浪",
  22. //火星1
  23. "你我之间差一百个泰森",
  24. //木星2
  25. "想要赢我就用拳头表示",
  26. //土星3
  27. "速度会让拳头变得更强",
  28. //天王星4
  29. "这不是回合制游戏懂吗",
  30. //海王星5
  31. "拳力的游戏里从未怕过",
  32. //黑洞6
  33. "力量是这场游戏的真理",
  34. //太阳系7
  35. "我在排行榜中一骑绝尘",
  36. //银河系8
  37. "此刻开始这里由我主宰",
  38. ];
  39. utils.isMobile(function () {
  40. Manager.sharelayoutManager = this;
  41. }.bind(this));
  42. // console.log("分享页面看见");
  43. if (soundM.sound!=null) {
  44. soundM.sound.playClose();
  45. }
  46. //流浪值
  47. let WanderingValue =this.WanderingValue= UtilsPrefabs.getNode("WanderingValue", this.node);
  48. //相差泰森那个
  49. let info = this.info = UtilsPrefabs.getNode("info", this.node);
  50. //飞过星球的图片node1
  51. let starImgNode = UtilsPrefabs.getNode("starImg", this.node);
  52. //飞过黑洞
  53. let heidong =this.heidong = UtilsPrefabs.getNode("heidong", starImgNode);
  54. //飞过太阳系
  55. let taiyang =this.taiyang = UtilsPrefabs.getNode("taiyang", starImgNode);
  56. //飞过银河系
  57. let yinhexi =this.yinhexi = UtilsPrefabs.getNode("yinhexi", starImgNode);
  58. //飞过的普通星球
  59. let FlyPassNormalStarNode =this.FlyPassNormalStarNode = UtilsPrefabs.getNode("NormalStar", starImgNode);
  60. //普通星球node遮罩
  61. let NormalStarMask = UtilsPrefabs.getNode("star1", FlyPassNormalStarNode);
  62. //飞过星球的图片1
  63. let starImg1 = this.starImg1 = UtilsPrefabs.getNode("starImg1", NormalStarMask);
  64. //飞过星球的图片2
  65. let starImg2 = this.starImg2 = UtilsPrefabs.getNode("starImg2", NormalStarMask);
  66. let powerValue = UtilsPrefabs.getNode("powerValue", this.node);
  67. //力量值
  68. let power = this.power = UtilsPrefabs.getNode("power", powerValue);
  69. let speedValue = UtilsPrefabs.getNode("speedValue", this.node);
  70. //速度值
  71. let speedLayout = UtilsPrefabs.getNode("layout", speedValue);
  72. let speed = this.speed= UtilsPrefabs.getNode("speed", speedLayout);
  73. //玩家名字
  74. let playername =this.playername = UtilsPrefabs.getNode("playername", this.node);
  75. let accuracyValue = UtilsPrefabs.getNode("accuracyValue", this.node);
  76. //准确度
  77. let accuracyLayout = UtilsPrefabs.getNode("layout", accuracyValue);
  78. let accuracy =this.accuracy= UtilsPrefabs.getNode("accuracy", accuracyLayout);
  79. //分享按钮
  80. let shareButton = UtilsPrefabs.getNode("shareButton", this.node);
  81. //分享按钮
  82. let shareButtonclose = UtilsPrefabs.getNode("shareButtonclose", this.node);
  83. let tNewNode = UtilsPrefabs.getNode("New Node", this.node);
  84. let tNewSprite = UtilsPrefabs.getNode("New Sprite", tNewNode);
  85. let tNewshare_ic = UtilsPrefabs.getNode("share_ic", tNewSprite);
  86. this.tNewSprite = UtilsPrefabs.getNode("New Sprite", tNewshare_ic);
  87. UtilsPrefabs.setOn(shareButton, function () {
  88. utils.isMobile(function () {
  89. this.captureScreenshot(function () {
  90. Manager.goShare();
  91. }.bind(this));
  92. }.bind(this));
  93. if (this.ShareButtonClick != null) {
  94. this.ShareButtonClick();
  95. }
  96. }.bind(this));
  97. UtilsPrefabs.setOn(shareButtonclose, function () {
  98. this.close();
  99. }.bind(this));
  100. //设置分享页面上面的数据
  101. this.initData();
  102. },
  103. close : function(){
  104. if (soundM.sound!=null) {
  105. soundM.sound.stop(soundM.sound.Close_ClipID);
  106. }
  107. if (this.ShareButtonClickclose != null) {
  108. this.ShareButtonClickclose();
  109. }
  110. },
  111. setShareButtonClickListeniner: function (ShareButtonClick) {
  112. this.ShareButtonClick = ShareButtonClick;
  113. },
  114. ShareButtonClick: function () {
  115. },
  116. setShareButtonClickcloseListeniner: function (ShareButtonClickclose) {
  117. this.ShareButtonClickclose = ShareButtonClickclose;
  118. },
  119. ShareButtonClickclose: function () {
  120. },
  121. captureScreenshot(call) {
  122. function callback() {
  123. var canvas = document.getElementById("GameCanvas");
  124. var base64 = canvas.toDataURL("imagea/png");
  125. cc.director.off(cc.Director.EVENT_AFTER_DRAW);
  126. // var frame = this.base64ToSpriteFrame(base64, (frame) => {
  127. // // this.NewsSprite.getComponent(cc.Sprite).spriteFrame = frame;
  128. // // console.log("走着了吗1",base64);
  129. // });
  130. // console.log("走着了吗2");
  131. if (call!=null) {
  132. ShareImage.img = base64;
  133. call();
  134. }
  135. }
  136. cc.director.on(cc.Director.EVENT_AFTER_DRAW, callback.bind(this));
  137. },
  138. base64ToSpriteFrame(base64, callback) {
  139. var img = new Image();
  140. img.src = base64;
  141. img.onload = function () {
  142. var texture = new cc.Texture2D();
  143. texture.initWithElement(img);
  144. texture.handleLoadedTexture();
  145. var newframe = new cc.SpriteFrame(texture);
  146. if (callback) callback(newframe);
  147. }
  148. },
  149. initData: function () {
  150. utils.getShareData(function (data) {
  151. // cc.log(UserInfo.PlayerGameData.currtag,"*****",data);
  152. this.WanderingValue.getComponent(cc.Label).string =data.power
  153. this.power.getComponent(cc.Label).string =data.everypowers_average+""
  154. this.speed.getComponent(cc.Label).string =data.speend_average+""
  155. this.accuracy.getComponent(cc.Label).string =data.types_average+""
  156. // this.starImg1.getComponent(cc.Sprite).spriteFrame = this.StarImgs[0];
  157. // this.starImg2.getComponent(cc.Sprite).spriteFrame = this.StarImgs[0];
  158. // this.info.getComponent(cc.Label).string = this.ShareTexts[0];
  159. this.setStarInfoAndImg(UserInfo.PlayerGameData.currtag);
  160. }.bind(this));
  161. this.playername.getComponent(cc.Label).string = UserInfo.Player.name
  162. utils.loadHttpSpriteFrame(UserInfo.Player.head, this.tNewSprite.getComponent(cc.Sprite));
  163. },
  164. setStarInfoAndImg: function (currtag) {
  165. //黑洞
  166. if (currtag == 6) {
  167. this.heidong.active = true;
  168. this.info.getComponent(cc.Label).string = this.ShareTexts[6];
  169. }
  170. //太阳系
  171. else if (currtag == 99) {
  172. this.taiyang.active = true;
  173. this.info.getComponent(cc.Label).string = this.ShareTexts[7];
  174. }
  175. //银河系
  176. else if (currtag == 100) {
  177. this.yinhexi.active = true;
  178. this.info.getComponent(cc.Label).string = this.ShareTexts[8];
  179. }
  180. //普通星球
  181. else {
  182. this.FlyPassNormalStarNode.active = true;
  183. this.starImg1.getComponent(cc.Sprite).spriteFrame = this.StarImgs[currtag];
  184. this.starImg2.getComponent(cc.Sprite).spriteFrame = this.StarImgs[currtag];
  185. this.info.getComponent(cc.Label).string = this.ShareTexts[currtag];
  186. }
  187. },
  188. // update (dt) {},
  189. });