WechatFriend.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var wechat = require('../net/WeChat');
  2. const ShareAction = require('../utils/ShareAction');
  3. const FriendSystemApi = require('../net/FriendSystemApi');
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. updateInterval: 0.2,
  8. updateTimer: 0,
  9. },
  10. onLoad() {
  11. },
  12. start() {
  13. if (window.wx != undefined) {
  14. this.tex = new cc.Texture2D();
  15. }
  16. },
  17. onEnable() {
  18. if (window.wx != undefined) {
  19. window.wx.postMessage({
  20. messageType: 1,
  21. key1: Global.wechatScoreKey,
  22. });
  23. }
  24. },
  25. onDisable() {
  26. if (window.wx != undefined) {
  27. window.wx.postMessage({
  28. messageType: 8,
  29. });
  30. }
  31. },
  32. update(dt) {
  33. if (!this.tex) {
  34. return;
  35. }
  36. // this._updateSubDomainCanvas(dt);
  37. this.updateTimer += dt;
  38. if (this.updateTimer < this.updateInterval) return; // we don't need to do the math every frame
  39. this.updateTimer = 0;
  40. var openDataContext = wx.getOpenDataContext();
  41. var sharedCanvas = openDataContext.canvas;
  42. sharedCanvas.innerWidth = 720;
  43. sharedCanvas.innerHeight = 900;
  44. this.tex.initWithElement(sharedCanvas);
  45. this.tex.handleLoadedTexture();
  46. this.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(this.tex);
  47. },
  48. inviteFriend() {
  49. wechat.inviteFriendPromise().then(() => {
  50. FriendSystemApi.shareSuccessNotice();
  51. });
  52. // cc.loader.loadRes('/prefabs/share_dialog', cc.Prefab, (error, prefab) => {
  53. // if (error === null) {
  54. // let shareDialog = cc.instantiate(prefab);
  55. // this.node.addChild(shareDialog);
  56. // shareDialog.getComponent('ShareDialog').showInviteFriend();
  57. // } else {
  58. // console.log(JSON.stringify(error));
  59. // }
  60. // });
  61. }
  62. });