//WeChat.js// Learn cc.Class://  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html// Learn Attribute://  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html// Learn life-cycle callbacks://  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.htmlvar curMod = cc.Class({    extends: cc.Component,    //微信接口    properties: {    },    statics: {        _instance: null,        _isAndroid: false,        InterstitialAdId: '',//插屏广告        RewardedVideoAdId: '',//视频广告        BannerIds: ['', ''],        //底部广告        ShareTitle: '',// 分享文案        ShareImgId: '', // 通过 MP 系统审核的图片编号        ShareImgUrl: '',//图片url        _wxUserInfo: {},        _systemInfo: {},        Instance() {            return curMod._instance;        },        GetInfo() {            return curMod._wxUserInfo;        },    },    onLoad() {        console.log('wechat onload, curMod._instance=', curMod._instance);        if (curMod._instance) {            return;        }        curMod._instance = this;        if (!window.wx) {            return;        }        //...        this._bannerAd = null;        this._intersitialAd = null;        this._rewardedVideoAd = null;        this.getWeiXinInfo();        if (curMod._isAndroid) {            //console.log('curMod._isAndroid...')            //cc.game.setFrameRate(40);        }        //cc.game.setFrameRate(45);        //load all ads        // setTimeout(() = {        //     this.createBannerAds();        //     this.createInterstitialAd();        //     this.createRewardedVideoAd();        // }, 200);    },    start() {        if (!window.wx) {            return;        }        this._bannerAds = [];        //加载广告        this.scheduleOnce(this.createBannerAds, 1);        this.scheduleOnce(this.createRewardedVideoAd, 3);        this.scheduleOnce(this.createInterstitialAd, 3);        //this.tex = new cc.Texture2D();    },    /*    _updateSubDomainCanvas() {        if (!this.tex) {            return;        }        var openDataContext = wx.getOpenDataContext();        var sharedCanvas = openDataContext.canvas;        this.tex.initWithElement(sharedCanvas);        this.tex.handleLoadedTexture();        this.display.spriteFrame = new cc.SpriteFrame(this.tex);    },*/    //存储信息,托管游戏数据    postDataToWX: function () {        if (!window.wx) {            return;        }        //向微信保存最高分数        var kvDateList = new Array();        var mypvpscore = require("PlayerMessages").Instance().getPVPMaxScore() + "";        var mypvptime = require("PlayerMessages").Instance().getPVPMinTime() + "";        //插入自己的分数        var myscore = require("PlayerMessages").Instance().getMaxScore() + "";        var mytime = require("PlayerMessages").Instance().getMinTime() + "";        kvDateList.push({            key: "mypvpscore",            value: mypvpscore        });        kvDateList.push({            key: "mypvptime",            value: mypvptime        });        kvDateList.push({            key: "myscore",            value: myscore        });        kvDateList.push({            key: "mytime",            value: mytime        });        //托管游戏数据        wx.setUserCloudStorage({            KVDataList: kvDateList,            success: function (res) {                console.log("wx.setUserCloudStorage success");                console.log(res);            },            fail: function (res) {                console.log("wx.setUserCloudStorage fail");                console.log(res);            }        });    },    //向子域通信    showHaoYouPVPPaihang: function () {        var openDataContext = wx.getOpenDataContext();        openDataContext.postMessage({            text: "showPVPRank",        });    },    showHaoYouPKPaihang: function () {        var openDataContext = wx.getOpenDataContext();        openDataContext.postMessage({            text: "showPKRank",        });    },    //微信分享按钮    WXshare: function () {        if (!window.wx) {            return;        }        cc.log('shareAppMessage...');        if (!window.wx) {            return;        }        window.wx.shareAppMessage({            title: curMod.ShareTitle,            imageUrlId: curMod.ShareImgId,            imageUrl: curMod.ShareImgUrl,        });        this._shareTime = new Date().getTime();    },    //插屏广告    showInterstitialAd() {        this._intersitialAd.show();    },    //视频广告    showRewardedVideoAd() {        //this.createRewardedVideoAd();        this._rewardedVideoAd.show();    },    //底部广告    showBannerAd(index) {        if (!window.wx) {            return;        }        for (let i = 0; i this._bannerAds.length; i++) {            if (i != index) {                this._bannerAds[i].hide();            }        }        if (this._bannerAds[index]) {            this._bannerAds[index].show();        }    },    //隐藏指定广告    hideBannerAd(index) {        if (!window.wx) {            return;        }        if (this._bannerAds && index this._bannerAds.length && this._bannerAds[index]) {            this._bannerAds[index].hide();        }    },    //隐藏所有广告    hideBannerAds: function () {        if (!window.wx) {            return;        }        if (this._bannerAds.length != null) {            if (this._bannerAds.length 0) {                for (var i = 0; i this._bannerAds.length; i++) {                    if (this._bannerAds && this._bannerAds[i]) {                        this._bannerAds[i].hide();                    }                }            }        微信小程序rewarded

http://www.xiaochengxub.com/read-105485.html