Can we use GoogleAds/AdMob/AdWhirl in cocos2d-android?

前端 未结 2 1171
醉酒成梦
醉酒成梦 2020-12-18 15:21

I want to add the Admob / AdWhirl into the GameLayer Scene.

I search over everywhere but couldn\'t find the way to do this work. I don\'t want to sw

相关标签:
2条回答
  • 2020-12-18 15:49

    as there is not layout xml file for cocos2d android you can add it progammatically. crate linear layout in onstart method itself.

    like this

    LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
                    getWindowManager().getDefaultDisplay().getWidth(),                        
                    getWindowManager().getDefaultDisplay().getHeight()+getWindowManager().getDefaultDisplay().getHeight()-50);
    
            adView = new AdView(SimpleGame.this, AdSize.BANNER, "your Ad ID");
    adView.setAdListener(SimpleGame.this);                            
            AdRequest request = new AdRequest();
            request.addTestDevice(AdRequest.TEST_EMULATOR);
            adView.loadAd(request);                
    
            CCDirector.sharedDirector().getActivity().addContentView(adView,adParams);
    

    this should be in try and catch.

    0 讨论(0)
  • 2020-12-18 16:11

    of course we can add admob and or any other lib in your cocos2d games activity class.

    You need to implement adlistener to your activity and add the adview in the OnStart() method of your game .

    0 讨论(0)
提交回复
热议问题