quick-cocos2dx 截屏分享到 微信、微博等社交网络
2014-03-28 23:40
531 查看
最近做游戏要用截屏分享的功能,于是在quick群中问群友怎么实现。感谢网友@当往事遇上风 给我的截屏代码。
思路:
1、先用qiuck截图保存本地
2、用luaj调用android的分享api 分享到社交网络
下面是代码
以上是quick中截屏并且保存到本地的代码 如果是android的系统的话 路径就是 /data/data/com.szfore.demo/files/share.jpg
这里只实现了android的分享, ios开发没弄过 不过 ios的分享应该是一样的原理 (好像ios的要用调用第三方的sdk才能进行分享没有android这样直接掉调用的api)
就上面的代码就可以实现截屏分享到社交网络拉
思路:
1、先用qiuck截图保存本地
2、用luaj调用android的分享api 分享到社交网络
下面是代码
function ShowView:shareButtonPressed() self:screen() local path = self:screen() if device.platform == "android" then -- Java 类的名称 local className = "com/szfore/xazc/Xazc" -- 调用 Java 方法 luaj.callStaticMethod(className, "Share", '', '()V') elseif device.platform == "ios" then -- print('分享到ios') end end
--截屏代码 有一个咔嚓的动画 function ShowScene:screen() local path = device.writablePath local size = CCDirector:sharedDirector():getWinSize() local screen = CCRenderTexture:create(size.width, size.height, 0) local temp = CCDirector:sharedDirector():getRunningScene() screen:begin() temp:visit() screen:endToLua() local pathsave = path.."/share.jpg" if screen:saveToFile('share.jpg', 0) == true then print(pathsave) end local colorLayer1 = display.newColorLayer(ccc4(0, 0, 0, 125)):addTo(self) colorLayer1:setAnchorPoint(ccp(0, 0)) colorLayer1:setPosition(ccp(0, display.height)) local colorLayer2 = display.newColorLayer(ccc4(0, 0, 0, 125)):addTo(self) colorLayer2:setAnchorPoint(ccp(0, 0)) colorLayer2:setPosition(ccp(0, - display.height)) transition.moveTo(colorLayer1, {y = display.cy, time = 0.5}) self:performWithDelay(function () transition.moveTo(colorLayer1, {y = display.height, time = 0.3}) end, 0.5) transition.moveTo(colorLayer2, {y = -display.cy, time = 0.5}) self:performWithDelay(function () transition.moveTo(colorLayer2, {y = -display.height, time = 0.3}) end, 0.5) end
以上是quick中截屏并且保存到本地的代码 如果是android的系统的话 路径就是 /data/data/com.szfore.demo/files/share.jpg
这里只实现了android的分享, ios开发没弄过 不过 ios的分享应该是一样的原理 (好像ios的要用调用第三方的sdk才能进行分享没有android这样直接掉调用的api)
<span style="white-space:pre"> </span>//分享到社交圈方法 public static void share(final String prms) { new Thread(new Runnable(){ public void run() { //String filePath = "/data/data/" + mActivity.getApplicationInfo().packageName+ "/files/share.png"; //String filePath = "file:" + mActivity.getFilesDir()+ "/share.png"; //String filePath = "/mnt//sdcard/share.png"; <span style="white-space:pre"> </span> //String newPath = copyImage(prms); <span style="white-space:pre"> </span> File f = new File(prms); <span style="white-space:pre"> </span> f.setExecutable(true,false); f.setReadable(true,false); f.setWritable(true,false); Intent intent = new Intent("android.intent.action.SEND"); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_SUBJECT, "分享"); intent.putExtra(Intent.EXTRA_TEXT, prms); if (f != null && f.exists() && f.isFile()) { <span style="white-space:pre"> </span> Log.e("path ","exists"); <span style="white-space:pre"> </span> intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(f)); } intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mActivity.startActivity(Intent.createChooser(intent, "分享")); } }).start(); }以上是android中的分享代码
就上面的代码就可以实现截屏分享到社交网络拉
相关文章推荐
- android cocos2dx游戏-添加截屏并分享微博功能
- android cocos2dx游戏-添加截屏并分享微博功能
- android cocos2dx游戏-添加截屏并分享微博功能
- android cocos2dx游戏-添加截屏并分享微博功能
- 不接sdk分享到微信,微博等第三方
- 基于js实现微信发送好友如何分享到朋友圈、微博
- js-分享功能(qq,微信,微博)
- 史上最详细Android集成QQ,微信,微博分享(不用第三方)持续更新中
- 微信、微博、Facebook、Twitter等社交媒体分享方案探索
- 分享到微信微博QQ空间JS代码大全
- iOS使用ShareSDK集成QQ,微信,微博等第三方分享
- Android 实现微信,微博,微信朋友圈,QQ分享的功能
- Android 分享实现,微信、微博、腾讯 不同分享方式不同内容
- 网页分享到微信、微博、QQ等
- Cocos2dx 接入友盟社会化分享-微信分享
- 关于XCode里导入cocos2dx项目接入微信分享SDK问题!
- 微信分享QQ分享微博分享时的图片压缩实现
- 分享到QQ,微信,微博等
- Android友盟集成QQ、微信、微博等第三方登录与分享
- 史上最详细Android集成QQ,微信,微博分享(不用第三方)持续更新中