zoukankan      html  css  js  c++  java
  • android cocos2dx游戏-加入截图和分享微博功能

    本文介绍怎样在游戏中添加分享功能,截屏后分享到微博及其他社交网络的功能。

    复制代码
    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

    在分享button初调用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));
    复制代码
  • 相关阅读:
    mdk3 工具使用-表白神器
    Crunch黑客神器-创造个性字典
    centos 自动挂载ISO
    渗透测试工具Nmap从初级到高级
    mui 点击长按复制文本
    JavaScript倒计时并刷新页面
    javascript单一复制粘贴
    jquery定义链接跳转的高亮显示
    JS判断移动端访问设备并加载对应CSS样式
    jquery刷新数据随机排列
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4748202.html
Copyright © 2011-2022 走看看