WechatFriend.js 1.7 KB

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