12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- var wechat = require('../net/WeChat');
- 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,
- });
- }
- },
- 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() {
- cc.loader.loadRes('/prefabs/share_dialog', cc.Prefab, (error, prefab) => {
- if (error === null) {
- let shareDialog = cc.instantiate(prefab);
- this.node.addChild(shareDialog);
- } else {
- console.log(JSON.stringify(error));
- }
- });
- }
- });
|