码迷,mamicode.com
首页 > 微信 > 详细

creator2.0.2 native游戏截屏微信分享

时间:2019-01-11 20:12:34      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:java   android   ima   fileutil   add   wxs   ini   move   javascrip   

cocos creator 2.0.2后 游戏内截屏,native微信SDK分享代码:
public static wxShareScreenShot(sType: number) {
  let node = new cc.Node();
  node.parent = cc.director.getScene();
  node.width = cc.view.getVisibleSize().width;
  node.x = cc.view.getVisibleSize().height;
  node.y = cc.view.getVisibleSize().width;
  node.height = cc.view.getVisibleSize().height;
  let camera = node.addComponent(cc.Camera);
  camera.cullingMask = 0xffffffff;
  let texture = new cc.RenderTexture();
  texture.initWithSize(node.width, node.height);
  camera.targetTexture = texture;
  camera.render(null);
  let data = texture.readPixels();
  let width = texture.width;
  let height = texture.height;
  data = this.filpYImage(data, width, height)
  let fileName = "result_share.jpg";
  let fullPath = jsb.fileUtils.getWritablePath() + fileName;
  if (jsb.fileUtils.isFileExist(fullPath)) {
    jsb.fileUtils.removeFile(fullPath);
  }
  let success = jsb.saveImageData(data, width, height, fullPath);
  if (success) {
    if(this.isAndroid){  
      jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "shareScreenShot","(Ljava/lang/String;Ljava/lang/String;)V",fullPath,sType.toString())
  }
  if (this.isIOS){
    jsb.reflection.callStaticMethod("VXManager", "shareScreenShot:" , sType.toString());
  }
  camera.destroy();
  texture.destroy();
  }
}

creator2.0.2 native游戏截屏微信分享

标签:java   android   ima   fileutil   add   wxs   ini   move   javascrip   

原文地址:https://www.cnblogs.com/shwhr/p/10256700.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!