您的位置:首页 > 移动开发 > Cocos引擎

android cocos2dx游戏-添加截屏并分享微博功能

2012-02-09 19:05 597 查看
  又到了选择的时候,元宵节,公交遇贼,钱包里的身份证银行卡,统统被偷;被偷了,瞬间感觉“轻松了”,任何情况下我都可能回到原点,不是吗?不要担心选择必然所要做的放弃。

public class ShareSupport {
// when you want to use share(),firstly you should init acty.
public static Activity acty;

public static void share() {
new Thread(new Runnable(){

@Override
public void run() {
Intent intent = new Intent("android.intent.action.SEND");
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
intent.putExtra(Intent.EXTRA_TEXT, "终于可以了!!!");
intent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:////data/data/" + acty.getApplicationInfo().packageName+ "/share.png"));
Log.i("debug", "/data/data/" + acty.getApplicationInfo().packageName+ "/share.png");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
acty.startActivity(Intent.createChooser(intent, "分享"));
}

}).start();
}
}


拿出以前写android时的分享代码。

#include "jni_interfaces.h"
#include <android/jni/JniHelper.h>

extern "C" {
void Share()
{
cocos2d::JniMethodInfo jni_method_info;
cocos2d::JniHelper::getStaticMethodInfo(jni_method_info,"com/hortor/support/ShareSupport","share","()V");

if (jni_method_info.methodID)
{
jni_method_info.env->CallStaticVoidMethod(jni_method_info.classID, jni_method_info.methodID);
}
}
}


c++代码越写越简洁了,删掉很多冗杂的地方。

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
Share();
CCLog("share ok");
#endif


在分享按钮初调用jni_interfaces中的Share()函数。



ok不过有时,程序分享完会出现崩溃。

02-10 10:22:59.976: A/libc(2565): Fatal signal 11 (SIGSEGV) at 0x54e68000 (code=1)

看到群里有问, 如何从序列帧中获取一张图片,我贴出游戏中截图代码:

CCSize size = CCDirector::sharedDirector()->getWinSize();
CCRenderTexture* in_texture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height,kCCTexture2DPixelFormat_RGBA8888);
in_texture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) );
in_texture->setPosition( ccp(size.width/2, size.height/2) );
in_texture->setAnchorPoint( ccp(0.5f,0.5f) );

in_texture->begin();
this->visit();
in_texture->end();

CCLog("%d",in_texture->saveBuffer(kCCImageFormatPNG,"share.png",0,0,800,480));


write by fgd
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: