Google AdMob implementation with GameMaker: Studio

Introduction

Here at NDXP Games, we recently finished development on Turtle Sprint and received approval from the Apple App Store to publish the game, which will go live on Wednesday, August 12, 2015! We chose to monetize our game using in-app advertisements. Turtle Sprint was made with GameMaker: Studio, an IDE we have become quite fond of.

The implementation of Google AdMob with GameMaker: Studio was a bit of a challenge, so this blog post has been dedicated to outlining the steps we took to achieve success.

Set Up Your AdMob Campaign

The first step is to sign up for a Google AdMob account and create an entry for your app. If you are using Google Analytics, be sure to use the same Google account that you used for Google Analytics to sign up for AdMob. After you login to AdMob, click the “Monetize” tab, followed by the “Monetize new app” button.

Chances are you are setting up AdMob before you have released your app, so you will need to configure the app manually. To do this, you will be required to:
Enter a name

  1. Choose a platform
  2. Generate an App tracking ID
  3. Choose your ad format
  4. Name the Ad unit

At this point, Google requires that you decide between two ad types for your ad unit: banner or interstitial. To use both, simply create another ad unit. We chose to use banner type ads for Turtle Sprint as we are aiming for an unobtrusive advertisement implementation. Be sure to make a note of your “Ad unit ID” because you will need it later in GameMaker: Studio.

After creating your “ad unit” you can choose your advertising content categories. Click on your app name on the left panel, and then click on the tab “Allow & block ads” to see the categories. There are sub-tabs listing general categories and sensitive categories; take a few minutes to explore them.

AdMob only allows you to block 50 categories so choose carefully in how you apply the blocks. Some categories will be listed as “Too big to block” but you can still block the subcategories within. Always keep your target market in mind and block categories based on what you think will be best for your players. Since we designed Turtle Sprint to be appropriate for almost all ages, we blocked many categories.

blog_admob_pic1

Import the GoogleMobileAds Extension

The current ad provider implementation method for GameMaker: Studio involves loading their demo project, exporting the GoogleMobileAds extension, then importing it into your project.

  1. Launch GameMaker: Studio
  2. Go to the “demos” tab
  3. Choose “Google_Mobile_Analytics” (this will load the demo project)
  4. In the left panel, expand “Extensions”
  5. Select the “GoogleMobileAdsExt” extension
  6. Right click on the extension and choose “Export extension”
  7. Save the .gmez file to your computer
  8. Close the demo project and open your own project
  9. Select “Extensions” from the left panel and right-click on it
  10. Choose “Import extension” and browse to the .gmez file

That completes the extension import process. Now you are ready to start adding the code that is needed to use the extension!

Initializing connection to AdMob and preloading ads

There are several pieces of code you will need to implement in GameMaker: Studio in order to display your ads correctly. The very first step is to initialize the connection with AdMob. Since we are using banner ads and not using interstitial ads, this only required the following code:

GoogleMobileAds_Init(“”);

I placed this line in a script called “scr_game_initialize” which runs one time at game launch. If you are planning to use interstitial ads, you will need to also include your interstitial add unit ID between the quotation marks.

For Turtle Sprint, we are only displaying ads at specific times, not throughout the game experience. This has a downside though; if you are only displaying ads at certain times, it is important to take advantage of all the screen time that is available. To achieve this, we decided to preload the ads before they needed to be displayed. I used the following code to preload the ad:

GoogleMobileAds_AddBannerAt(“ad-unit-id-here”, GoogleMobileAds_Leaderboard, -1, -1);

Note that the first argument is the ad unit ID, the second argument specifies the size of the banner ad requested, and the third set of arguments are the X and Y coordinates for the ad. The advantage of loading an ad at (-1, -1) is that the ad is not displayed at all since (-1, -1) is considered to be outside the viewable area of the screen. I placed this code in a script that I could call at an appropriate time to load the ad before it was needed.

Displaying the Ad

In the following piece of code, you will see that the preloaded ad is moved to a visible coordinate position on the screen:

switch (os_device) {
case device_ios_ipad: GoogleMobileAds_MoveBanner(148, 519); break;
case device_ios_ipad_retina: GoogleMobileAds_MoveBanner(296, 1038); break;
}

In the snippet above, you will notice that I used the os_device variable to detect whether the iPad has a retina display or not, and provide the correct coordinates for the banner in either case. This code was placed in a script that could be called when the player reaches the “level complete” or “level failed” screens.

blog_admob_pic2

When the player leaves the “level complete” or “level failed” screen, we use the following code to remove the ad from view, and preload a new banner for the next time an ad will display:

GoogleMobileAds_RemoveBanner();
GoogleMobileAds_AddBannerAt(“ad-unit-id-here”, GoogleMobileAds_Leaderboard, -1, -1);


Conclusion

Implementing in-app advertisements with AdMob and GameMaker: Studio was a little challenging, but overall I felt that it went very smoothly. In a future blog post, I will detail how I set up an in-app purchase to remove the ads, and the hurdle I ran into after submitting our game to the Apple App Store’s  review team!

Resources

YoYo Games Knowledgebase: Google Mobile Advertising http://help.yoyogames.com/entries/24461331-Ads-Google-Mobile-Advertising-v1-3

Google AdMob Help Center
https://support.google.com/admob/#topic=2740022

Leave a Reply

Your email will not be published. Name and Email fields are required.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>