九 CocosEditor基础教程第二季 之添加百度-腾讯-360-豌豆荚的第三方sdk

前言:

这一节主要讲解如何添加第三方sdk;主要通过以前的2048项目,另外cocos2dx-android.jar源代码也开源出去,想具体了解cocos引擎和android是如何交互的 可以研究cocos2dx-android代码,也存放在下面链接里面;



代码下载

https://github.com/makeapp/cocoseditor-2048 (名称对应各平台sdk 比如2048-android-baidu, 2048-android-360等)




图片快照




分析

1 请使用项目里面最新的cocos2dx-android.jar库 如果你要在其他项目中添加sdk 也需要覆盖新的cocos2dx-android库


2 添加sdk基本类似,首先整个activity是在framelayer上,opengl游戏也放置在framelayer上,我们添加的sdk只要新建一个relativelayer,放置在里面就可以了;

以百度sdk为例子,覆盖init函数,frameLayer层加了一个sdkLayer,在sdkLayer里面嵌入bannerlayer就行,因为封装好了cocos2dx-android.jar 一切就好办多了

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public FrameLayout init() {
        FrameLayout frameLayout = super.init();
        RelativeLayout sdkLayer = new RelativeLayout(this);
        frameLayout.addView(sdkLayer);

//        RelativeLayout rlMain = new RelativeLayout(this);
//        rlMain.setHorizontalGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL);
//        // 创建广告View
//        AdView.setAppSid(this, "b1067edd");
//        AdView.setAppSec(this, "b1067edd");
//        AdView adView = new AdView(this);
//        rlMain.addView(adView);
//        frameLayout.addView(rlMain);
//        return frameLayout;

        //banner
        RelativeLayout bannerLayer = new RelativeLayout(this);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 150);
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        bannerLayer.setLayoutParams(params);
        bannerLayer.setGravity(Gravity.CENTER);
        sdkLayer.addView(bannerLayer);

        // 创建广告View
        AdView.setAppSid(this, "1003b991");  //b1067edd
        AdView.setAppSec(this, "1003b991");  //b1067edd
        AdView adView = new AdView(this);
        bannerLayer.addView(adView);


        //interstitial

        //appWall

//        actionFromCocos2djs(frameLayout);

        return frameLayout;
    }

具体的实现还是看代码 这样来的快;



猜你喜欢

转载自blog.csdn.net/touchsnow/article/details/38296479