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));
    复制代码
  • 相关阅读:
    Go语言之基本数据类型
    GO语言结构、变量和常量
    Go语言介绍及环境准备
    js中的 || 和 &&
    面试记录
    惠普打印机M180N,不小心点了 升级(含固件)之后,出现错误码ER11 不是别国产硒鼓,降级固件地址如下:
    C#调用webservice wsdl文件
    C# 利用VS自带的WSDL工具生成WebService服务类
    GridView添加统计(合计)行
    联通物联网卡ICCID号校验位算法
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4748202.html
Copyright © 2011-2022 走看看