Microsoft pubCenter adsworking with Cocos2d-XNA (finally!)

Topics: Windows Phone 8
Jan 21, 2014 at 5:04 AM
Edited Jan 21, 2014 at 5:06 AM
After a few hours, I finally got it to work.

,1. Follow the Nokia guide to creating a pubcenter account including app and adunit IDs
,2. Add references to Microsoft.Advertising.Mobile.UI and Microsoft.Advertising.Mobile to the project
,3. Make sure the following capabilities are declared in WPAppManifest.xml:
,4. In GamePage.xaml, replace this:
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <DrawingSurface x:Name="XnaSurface"/>
with this:
    <DrawingSurfaceBackgroundGrid x:Name="XnaSurface" Background="Transparent">
        <Canvas x:Name="Canvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
,5. In GamePage.xaml.cs, add references to Microsoft.Advertising.Mobile and Microsoft.Advertising.Mobile.UI and then add a Loaded event handler with the following code:
public GamePage()
            _game = XamlGame<Game1>.Create("", this);
            Loaded += GamePage_Loaded;

        void GamePage_Loaded(object sender, RoutedEventArgs e)
            AdControl adControl;
            adControl = new AdControl("test_client", "Image480_80", true);
            adControl.Width = 480;
            adControl.Height = 80;
,6. Replace "test_client" and "Image480_80" with your app and adunit IDs from pubCenter, and make sure you set the width and height to the correct size of the ad you chose on pubCenter.
,7. Since the ad control paints on top of the Cocos2D gaming surface, you'll have to write code to show/hide the adcontrol at the right time/place in your game.
Jan 21, 2014 at 5:35 AM
cool! I tried this for Santa Shooter and never got it to work. Never thought to revert the game page back to using the surface grid. excellent! We should make a template for WindowsPhone8WithAds games.