Adding Ads for Windows Phone 8 Game Made With Construct 2


Ok, so I just finished a post on Adding Ads for a Windows 8.1 Game Made With Construct 2, and in that article I mentioned that there is currently no way to implement ads in a Windows Phone 8.1 game made with Construct 2 because there is not yet an ads SDK that supports Windows Phone 8.1 projects written in Javascript.  So, I figure I would do the next best thing and show you how to implement ads in a Windows Phone 8 game.  This might seem like a hassle, but honestly it’s pretty minimal work.  Basically, you export as a Windows Phone 8 app, open up in Visual Studio, make a couple of changes, and boom…there you go!

To begin we need to export our project to a Windows Phone 8 app.  In my previous tutorials, I have been working with a game called Golden Ball, so I will continue to use that project.  If you have been worked through all of the Windows 8 Object tutorials or the Ads for Windows 8.1 tutorial, you can continue with that project.  Otherwise, you can find a start project here, Golden Ball Ads Starter.

 

Feel free to open the project up and take a look around, but we don’t actually need to make any changes in Construct 2 right as all of our changes will take place in Visual Studio.  So, we need to export our project to open up the source code in Visual Studio.  Take a look here for my post on Exporting a Construct 2 Project to Windows.  You should export your project as Windows Phone 8.  After you export, open up your Visual Studio solution file (.sln).  You should see a solution as below.

 

Screenshot (258)

 

NoticeI had the WMAppManifest highlighted in the Solution Explorer in the previous picture.  Go ahead and open that file up and navigate to the Capabilities tab.  For ads to work, we have to select certain capabilities.  Check that all of these capabilities are checked below in your Capabilities tab.

  • ID_CAP_IDENTITY_USER
  • ID_CAP_MEDIALIB_PHOTO
  • ID_CAP_NETWORKING
  • ID_CAP_PHONEDIALER
  • ID_CAP_WEBBROWSERCOMPONENT

 

Screenshot (246)

 

Now that we have the necessary capabilities selected, open up your MainPage.XAML, which should look like this.  It mainly consists of a WebBrowser control that basically wraps out game (as a web app) in a XAML control.

 

Screenshot (250)

 

What we want to do is to add another row to our grid for our ad banner.  You can either use the visual editor to add a row or copy this code above the WebBrowser control.  The result is shown in the image below.

 

<Grid.RowDefinitions>
     <RowDefinition Height="700*"/>
     <RowDefinition Height="100*"/>
     <RowDefinition/>
</Grid.RowDefinitions>

 

Screenshot (252)

 

If you used the Visual Editor, you might notice that a Grid.RowSpan property was added to your WebBrowser control.  If so, make sure that it is set to 1.

 

 Screenshot (253)

 

Now, let’s add the control for our ads.  The easiest way for me is to open up the toolbox and scroll down to the AdControl shown at the bottom, then drag it on the Visual Editor.  Keep in mind that you must have all of the Windows Phone 8 tooling installed.

 

 Screenshot (254)

 

After you drag the AdControl control on the Visual Editor it creates XAML code for you as below.

 Screenshot (255)

 

Notice above that there is are properties for both Application ID and Ad Unit ID.  We can leave these alone for testing (in fact, test ads won’t show up in the emulator if you use real Application IDs and Ad Unit IDs).  However, when it comes time to publish, you will want to fill these properties appropriately.  To set up an ad unit in PubCenter, you can read my post, Monetization with Ads - Creating App ID and Ad Unit ID.

Moving on, the generated code for the AdControl is giving us a lot of properties that we don’t necessarily need, so here is how I cleaned it up.  I set Vertical and Horizontal Alignment to center, the width and height to 480 and 80 (the same size as the banner I created in PubCenter), and the set the Row to 1.  After you clean it up, it should like this.

 

 Screenshot (256)

 

Now, go ahead and run your game in the Windows Phone Emulator, and you should see the Microsoft test banner as shown below!

 

 Screenshot (257)

 

Do keep in mind that when you publish you will need to add real Application ID and Ad Unit ID. Don’t forget that! 

 

As always comment below or find me on twitter, @jamesqquick, with any questions, comments, or concerns.

Comments (2)
  1. Vu Truong Giang says:

    Great blog! But could you please tell me how to add Admob advertisement in my game? Because I can't complete my tax profile in pubCenter without SSN.

  2. James Quick says:

    Hey Vu, thanks for reading and commenting!  Unfortunately, I have yet to work with admob, so I can't help you there.

Comments are closed.

Skip to main content