Geeks With Blogs

News

Google My Blog

Catch me at: The List!


My InstallScript Utility Belt My Amazon Wishlist
My Standard Disclaimer


Archives
Chris G. Williams Beware: I mix tech and personal interests here.

This is how it should work:

In your game project, set a project reference to Microsoft.Advertising.Mobile.Xna (This will point to whatever folder you installed the SDK to!)

Next, add a using statement at the top of your game:

using Microsoft.Advertising.Mobile.Xna;

Next, add these variable declarations at the class level:

        AdManager adManager;
        Ad bannerAd;

Next, add some constants (also at the class level) to store your Application ID and Ad Unit ID from the pubcenter.microsoft.com site. (You have to have these!!)

        const string AppID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";  //use your own
        const string AdUnitID = "xxxxx"; //use your own

In your Game1 constructor, add the following:

            adManager = new AdManager(this, AppID);
            adManager.TestMode = false;  // this part is important if you want to see your ads and not the test ad

            Components.Add(adManager);

Finally, in the LoadContent() method, add these lines:

            bannerAd = adManager.CreateAd(AdUnitID,
                                          new Rectangle(0, 20, GraphicsDevice.Viewport.Bounds.Width, 120),
                                          RotationMode.Manual,
                                          false);

You have to use RotationMode.Manual in XNA (which means you'll need to set your own timer and call the RequestNextAd() method at a sensible interval. (Roughly 30 seconds or so)

That's it!

THINGS TO BE AWARE OF:

  1. You need to set up your app and ad units in the Pubcenter website (URL above) in order to get the numbers for the AppID and AdUnitID.
  2. It can take up to 30 minutes for ads to start appearing in your app or game after you create the ad units.
  3. There is a bug that occasionally affects text ads. Since these depend on spritefonts to display, text ads with special characters may not show up properly.

 

Posted on Sunday, March 20, 2011 3:08 PM Game Development | Back to top


Comments on this post: Using the Advertising SDK with XNA on Windows Phone 7

# re: Using the Advertising SDK with XNA on Windows Phone 7
Requesting Gravatar...
If you are looking for an example of integrating the latest ad SDK with Microsoft's GameStateManagementSample that utilizes a screen manager, multiple screens, and the actual gameplayScreen, there is a good tutorial here:

Game State Management Sample with Ads
Left by Robert LaForge on Aug 21, 2011 4:14 PM

# re: Using the Advertising SDK with XNA on Windows Phone 7
Requesting Gravatar...
are you veteriner dos and cads is live
Left by veteriner on Sep 25, 2011 4:54 PM

# re: Using the Advertising SDK with XNA on Windows Phone 7
Requesting Gravatar...
like this post. I have this in many days ago but not happy with the result! try now with this.
Left by maquinas de coser on Mar 20, 2012 8:13 AM

Your comment:
 (will show your gravatar)


Copyright © Chris G. Williams | Powered by: GeeksWithBlogs.net