CocosSahrp and Admob

Hi together,

i am currently working on an android app with CocosSharp and i added AdMob. I had a little problem to show the ad in my game because it seems that the CocosSharp Layer is in front and the AdMobs "z-index" is lower. I found a solution for this Problem: In a Schedule i call ad.BringToFront(); after a few seconds but this seems not to be a good solution. Any suggestions for this problem or a better solution?

How i add the AdMob:

Android.Graphics.Point size = new Android.Graphics.Point(); activity.WindowManager.DefaultDisplay.GetSize(size); ViewGroup.LayoutParams adParams = new ViewGroup.LayoutParams( size.X, 100); var ad = new AdView (activity); ad.AdSize = AdSize.SmartBanner; ad.AdUnitId = activity.Resources.GetString (Resource.String.admobId); var requestbuilder = new AdRequest.Builder (); ad.LoadAd (requestbuilder.Build ()); activity.AddContentView(ad,adParams);

My Solution to get it to the front:

Schedule (t => { playTime += t; if (playTime > 3 ) { adMob.BringToFront(); } }, 1.0f);

Answers

  • MatMalMatMal USMember

    Hi Andreas,

    can you please share with me a test project included to admob ( even with this implementation )? We long can't find a normal way to integrate advertising in our game.

  • Hi MatMal,

    sorry for my late response. I have created a little test project with cocossharp and admob which only starts cocosharp and shows the add: https://github.com/Crofly/CocosSharpAdMobExample

    In the GameLayer.cs you have to enter your admob id at this line: ad.AdUnitId = "YOUR ADD ID HERE";

    I hope this helps.

  • MatMalMatMal USMember

    Hi Andreas,

    Thank you so much! This will help not only me, but many Cocos Sharp developers!) Excellent work .

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Andreas

    Thank you for that. Just to let everyone know that the CocosSharp samples repo is open to anyone that would like to put their samples out there or demonstrate certain ways to do things. This repo is and should be a community effort.

    Thanks again Andreas.

  • wo997wo997 Member ✭✭

    @AndreasSchwarz said:
    Hi MatMal,

    sorry for my late response. I have created a little test project with cocossharp and admob which only starts cocosharp and shows the add: https://github.com/Crofly/CocosSharpAdMobExample

    In the GameLayer.cs you have to enter your admob id at this line: ad.AdUnitId = "YOUR ADD ID HERE";

    I hope this helps.

    Thank you for that solution, I hope this will work, I just implemented it and I wait for admob to update

Sign In or Register to comment.