WechatFriend.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. start() {
  10. if (window.wx != undefined) {
  11. this.tex = new cc.Texture2D();
  12. }
  13. },
  14. onEnable() {
  15. if (window.wx != undefined) {
  16. window.wx.postMessage({
  17. messageType: 1,
  18. key1: Global.wechatScoreKey,
  19. });
  20. }
  21. },
  22. update(dt) {
  23. if (!this.tex) {
  24. return;
  25. }
  26. // this._updateSubDomainCanvas(dt);
  27. this.updateTimer += dt;
  28. if (this.updateTimer < this.updateInterval) return; // we don't need to do the math every frame
  29. this.updateTimer = 0;
  30. var openDataContext = wx.getOpenDataContext();
  31. var sharedCanvas = openDataContext.canvas;
  32. sharedCanvas.innerWidth = 720;
  33. sharedCanvas.innerHeight = 900;
  34. this.tex.initWithElement(sharedCanvas);
  35. this.tex.handleLoadedTexture();
  36. this.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(this.tex);
  37. },
  38. inviteFriend() {
  39. cc.loader.loadRes('/prefabs/share_dialog', cc.Prefab, (error, prefab) => {
  40. if (error === null) {
  41. let shareDialog = cc.instantiate(prefab);
  42. this.node.addChild(shareDialog);
  43. } else {
  44. console.log(JSON.stringify(error));
  45. }
  46. });
  47. }
  48. });