Generating Revenue From Your Cocos2d-x Games on Windows Devices

The Microsoft Ads framework is fast becoming an essential lever for game developers on Windows devices to generate revenue. .

This first of a series of articles on the topic aims to help you implement this feature in your Cocos2d-x game for Windows Phone or Windows Store, to make more money from your games through In-app purchase and advertising.

Adding Ads Into Your Application

The code we use to integrate ads runs on Cocos2d-x v2 which is available on GitHub.

To display Ads from Microsoft pubCenter, the general principle is pretty easy: just add the Ads control to your XAML file. When you generate a Windows project with Cocos2d-x tools, your solution contains specific files to describe your screen layout (XAML files) independently of your Cocos2d-x code (XAML is your native wrapper for your Cocos2d-x code).

For Windows RT (8 or 8.1), in the XAML file you want display the ads, just add the AdControl. Ads are often displayed within the main menu, or within the bottom portion of the game scene screen. For this purpose, you need to reserve a place in your design defining Ads size as documented here.

Adding AdControl within your XAML file looks like this:

<UI:AdControl ApplicationId="d25517cb-12d4-4699-8bdc-52040c712cab" AdUnitId="10043104" HorizontalAlignment="Left" Height="250" Margin="314,128,0,0" VerticalAlignment="Top" Width="727"/>

Run the application and you will then view a display sample of the ad within your application:

clip_image002

For Windows Phone (8)

Use the same approach, just add the AdControl on the screen you want, and reserve some space for it in your design, you may have to reduce the size of the drawing surface.

clip_image004

Or add this lines in the xaml file of your screen definition:

<phone:PhoneApplicationPage

[…]    

  xmlns:UI="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI" <--- Add this line if you want the control created in the Xaml, not needed if the AD control is created in the code

[…]    

    <!--LayoutRoot is the root grid where all page content is placed-->

    <DrawingSurfaceBackgroundGrid x:Name="DrawingSurfaceBackground" Loaded="DrawingSurfaceBackground_Loaded">

[…]

        <Canvas x:Name="Canvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> <--- Add this line to host the ADcontrol

 

In DrawingSurfaceBackground_Loaded() create and add the AdControl:

            AdControl adControl;

            adControl = new AdControl("test_client", "Image480_80", true);

            adControl.Width = 480;

            adControl.Height = 80;

            this.Canvas.Children.Add(adControl);

 

 

At runtime, this simple banner will appear on the screen. Click on it when running in debug or test mode to redirect to Internet Explorer.

clip_image005

 

Once you have created an account on Microsoft pubCenter portal, you will be able to start making money.

 

Additional Resources

A complete overview of the Microsoft Advertising SDK for Windows 8.1 is available on MSDN

Microsoft Advertising SDK for Windows 8.1

XAML - Windows 8.1

XAML (.NET) - Windows 8.0

Windows Phone 8.1 XAML Apps -- Integrating AdControl Using XAML Markup

Windows Phone 8.1 XAML Apps -- Integrating AdControl Using the Visual Designer

To create an account and use the Microsoft pubCenter portal, visit http://adsinapps.microsoft.com/en-us

Important Note: The Microsoft Advertising SDK is already included in Visual Studio 2013. There is no need to install it separately. Just use the Microsoft Advertising AdControl and go! You will simply need to add internet capabilities into your app to allow ads to be delivered … from the Internet J

clip_image007

If you are using an older version of Visual Studio, you will need to install the Microsoft Advertising SDK. Once installed, you should also add it as a reference in your project:

clip_image009

Of course, the Ads flow will become real after you have activated your application in the pubCenter portal and when it will be purchased/downloaded from the Windows Stor. Use the Microsoft pubCenter portal to ‘monetize’ the application. Take a look at it.

clip_image011

Please share any feedback about your experiences as comments to this blog or at the project site. We look forward to hearing from you about the ways in which you use this information to view ads within your Cocos2d-x application on Windows Phone and/or Windows 8.

Eric Mittelette

Microsoft Open Technologies, Inc.
A subsidiary of Microsoft Corporation


One thought on “Generating Revenue From Your Cocos2d-x Games on Windows Devices

  1. Pingback: Dew Drop – June 11, 2014 (#1795) | Morning Dew

Leave a Reply