123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- var wechat = require('../net/WeChat');
- const ShareAction = require('../utils/ShareAction');
- const FriendSystemApi = require('../net/FriendSystemApi');
- cc.Class({
- extends: cc.Component,
- properties: {
- updateInterval: 0.2,
- updateTimer: 0,
- },
- onLoad() {
- },
- start() {
- if (window.wx != undefined) {
- this.tex = new cc.Texture2D();
- }
- },
- onEnable() {
- if (window.wx != undefined) {
- window.wx.postMessage({
- messageType: 1,
- key1: Global.wechatScoreKey,
- });
- }
- },
- onDisable() {
- if (window.wx != undefined) {
- window.wx.postMessage({
- messageType: 8,
- });
- }
- },
- update(dt) {
- if (!this.tex) {
- return;
- }
- // this._updateSubDomainCanvas(dt);
- this.updateTimer += dt;
- if (this.updateTimer < this.updateInterval) return; // we don't need to do the math every frame
- this.updateTimer = 0;
- var openDataContext = wx.getOpenDataContext();
- var sharedCanvas = openDataContext.canvas;
- sharedCanvas.innerWidth = 720;
- sharedCanvas.innerHeight = 900;
- this.tex.initWithElement(sharedCanvas);
- this.tex.handleLoadedTexture();
- this.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(this.tex);
- },
- inviteFriend() {
- wechat.inviteFriendPromise().then(() => {
- FriendSystemApi.shareSuccessNotice();
- });
- // cc.loader.loadRes('/prefabs/share_dialog', cc.Prefab, (error, prefab) => {
- // if (error === null) {
- // let shareDialog = cc.instantiate(prefab);
- // this.node.addChild(shareDialog);
- // shareDialog.getComponent('ShareDialog').showInviteFriend();
- // } else {
- // console.log(JSON.stringify(error));
- // }
- // });
- }
- });
|