// Learn cc.Class: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html // Learn Attribute: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { // ShareTexts:null, StarImgs: [cc.SpriteFrame], }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start() { this.ShareTexts=[ //月球0 "送ta上去月球表面流浪", //火星1 "你我之间差一百个泰森", //木星2 "想要赢我就用拳头表示", //土星3 "速度会让拳头变得更强", //天王星4 "这不是回合制游戏懂吗", //海王星5 "拳力的游戏里从未怕过", //黑洞6 "力量是这场游戏的真理", //太阳系7 "我在排行榜中一骑绝尘", //银河系8 "此刻开始这里由我主宰", ]; utils.isMobile(function () { Manager.sharelayoutManager = this; }.bind(this)); // console.log("分享页面看见"); if (soundM.sound!=null) { soundM.sound.playClose(); } //流浪值 let WanderingValue =this.WanderingValue= UtilsPrefabs.getNode("WanderingValue", this.node); //相差泰森那个 let info = this.info = UtilsPrefabs.getNode("info", this.node); //飞过星球的图片node1 let starImgNode = UtilsPrefabs.getNode("starImg", this.node); //飞过黑洞 let heidong =this.heidong = UtilsPrefabs.getNode("heidong", starImgNode); //飞过太阳系 let taiyang =this.taiyang = UtilsPrefabs.getNode("taiyang", starImgNode); //飞过银河系 let yinhexi =this.yinhexi = UtilsPrefabs.getNode("yinhexi", starImgNode); //飞过的普通星球 let FlyPassNormalStarNode =this.FlyPassNormalStarNode = UtilsPrefabs.getNode("NormalStar", starImgNode); //普通星球node遮罩 let NormalStarMask = UtilsPrefabs.getNode("star1", FlyPassNormalStarNode); //飞过星球的图片1 let starImg1 = this.starImg1 = UtilsPrefabs.getNode("starImg1", NormalStarMask); //飞过星球的图片2 let starImg2 = this.starImg2 = UtilsPrefabs.getNode("starImg2", NormalStarMask); let powerValue = UtilsPrefabs.getNode("powerValue", this.node); //力量值 let power = this.power = UtilsPrefabs.getNode("power", powerValue); let speedValue = UtilsPrefabs.getNode("speedValue", this.node); //速度值 let speedLayout = UtilsPrefabs.getNode("layout", speedValue); let speed = this.speed= UtilsPrefabs.getNode("speed", speedLayout); //玩家名字 let playername =this.playername = UtilsPrefabs.getNode("playername", this.node); let accuracyValue = UtilsPrefabs.getNode("accuracyValue", this.node); //准确度 let accuracyLayout = UtilsPrefabs.getNode("layout", accuracyValue); let accuracy =this.accuracy= UtilsPrefabs.getNode("accuracy", accuracyLayout); //分享按钮 let shareButton = UtilsPrefabs.getNode("shareButton", this.node); //分享按钮 let shareButtonclose = UtilsPrefabs.getNode("shareButtonclose", this.node); let tNewNode = UtilsPrefabs.getNode("New Node", this.node); let tNewSprite = UtilsPrefabs.getNode("New Sprite", tNewNode); let tNewshare_ic = UtilsPrefabs.getNode("share_ic", tNewSprite); this.tNewSprite = UtilsPrefabs.getNode("New Sprite", tNewshare_ic); UtilsPrefabs.setOn(shareButton, function () { utils.isMobile(function () { this.captureScreenshot(function () { Manager.goShare(); }.bind(this)); }.bind(this)); if (this.ShareButtonClick != null) { this.ShareButtonClick(); } }.bind(this)); UtilsPrefabs.setOn(shareButtonclose, function () { this.close(); }.bind(this)); //设置分享页面上面的数据 this.initData(); }, close : function(){ if (soundM.sound!=null) { soundM.sound.stop(soundM.sound.Close_ClipID); } if (this.ShareButtonClickclose != null) { this.ShareButtonClickclose(); } }, setShareButtonClickListeniner: function (ShareButtonClick) { this.ShareButtonClick = ShareButtonClick; }, ShareButtonClick: function () { }, setShareButtonClickcloseListeniner: function (ShareButtonClickclose) { this.ShareButtonClickclose = ShareButtonClickclose; }, ShareButtonClickclose: function () { }, captureScreenshot(call) { function callback() { var canvas = document.getElementById("GameCanvas"); var base64 = canvas.toDataURL("imagea/png"); cc.director.off(cc.Director.EVENT_AFTER_DRAW); // var frame = this.base64ToSpriteFrame(base64, (frame) => { // // this.NewsSprite.getComponent(cc.Sprite).spriteFrame = frame; // // console.log("走着了吗1",base64); // }); // console.log("走着了吗2"); if (call!=null) { ShareImage.img = base64; call(); } } cc.director.on(cc.Director.EVENT_AFTER_DRAW, callback.bind(this)); }, base64ToSpriteFrame(base64, callback) { var img = new Image(); img.src = base64; img.onload = function () { var texture = new cc.Texture2D(); texture.initWithElement(img); texture.handleLoadedTexture(); var newframe = new cc.SpriteFrame(texture); if (callback) callback(newframe); } }, initData: function () { utils.getShareData(function (data) { // cc.log(UserInfo.PlayerGameData.currtag,"*****",data); this.WanderingValue.getComponent(cc.Label).string =data.power this.power.getComponent(cc.Label).string =data.everypowers_average+"" this.speed.getComponent(cc.Label).string =data.speend_average+"" this.accuracy.getComponent(cc.Label).string =data.types_average+"" // this.starImg1.getComponent(cc.Sprite).spriteFrame = this.StarImgs[0]; // this.starImg2.getComponent(cc.Sprite).spriteFrame = this.StarImgs[0]; // this.info.getComponent(cc.Label).string = this.ShareTexts[0]; this.setStarInfoAndImg(UserInfo.PlayerGameData.currtag); }.bind(this)); this.playername.getComponent(cc.Label).string = UserInfo.Player.name utils.loadHttpSpriteFrame(UserInfo.Player.head, this.tNewSprite.getComponent(cc.Sprite)); }, setStarInfoAndImg: function (currtag) { //黑洞 if (currtag == 6) { this.heidong.active = true; this.info.getComponent(cc.Label).string = this.ShareTexts[6]; } //太阳系 else if (currtag == 99) { this.taiyang.active = true; this.info.getComponent(cc.Label).string = this.ShareTexts[7]; } //银河系 else if (currtag == 100) { this.yinhexi.active = true; this.info.getComponent(cc.Label).string = this.ShareTexts[8]; } //普通星球 else { this.FlyPassNormalStarNode.active = true; this.starImg1.getComponent(cc.Sprite).spriteFrame = this.StarImgs[currtag]; this.starImg2.getComponent(cc.Sprite).spriteFrame = this.StarImgs[currtag]; this.info.getComponent(cc.Label).string = this.ShareTexts[currtag]; } }, // update (dt) {}, });