Skip to content

GameMaker Plugin

Shimon Shnitzer edited this page Mar 28, 2017 · 8 revisions

For both Android and iOS:

Installation

  1. The MobFoxForGameMaker.gmez is the native extension you need to incorporate in your application. Download it, and save it on your computer. You can also use the “MobFoxDemo” demo project as an example app to start from.

  2. To import the extension to your new/existing project, right-click on "Extensions" in the left pane of GameMaker IDE, and select "Import extension", then select the MobFoxForGameMaker.gmez file.

  3. To use the demo project - download the ZIP or clone it, then open it in GameMaker IDE.

Banner ads

  1. To show a banner ad - call create_banner("<hash code>",x,y,width,height)

  2. To receive callbacks - create a SOCIAL event:

    The event receives 2 parameters - 'type' and 'data' (if needed)

     var type = ds_map_find_value(async_load,"type");
    
     if (type == "bannerError") {
         // an error occurred - read the 'data' param to get the cause
         var data = ds_map_find_value(async_load,"data");
         show_toast("bannerError: "+data);
     }
    
     if (type == "bannerReady") {
         // banner loaded successfully
         show_toast("bannerReady");
     }
    
     if (type == "bannerClosed") {
         show_toast("bannerClosed");
     }
    
     if (type == "bannerClicked") {
         // banner clicked
         show_toast("bannerClicked");
     }
     if (type == "bannerFinished") {
         // banner finished
         show_toast("bannerFinished");
     }
    
    
  3. To hide or unhide a banner - call hide_banner() or unhide_banner()

Interstitial ads

  1. To show an interstitial ad - call create_interstitial("<hash code>")

  2. To receive callbacks - create a SOCIAL event:

    The event receives 2 parameters - 'type' and 'data' (if needed)

     var type = ds_map_find_value(async_load,"type");
    
     if (type == "interstitialError") {
         // an error occurred - read the 'data' param to get the cause
         var data = ds_map_find_value(async_load,"data");
         show_toast("interstitialError: "+data);
     }
    
     if (type == "interstitialReady") {
         // interstitial loaded successfully
         show_toast("interstitialReady");
    
         // called to display the loaded interstitial
         show_interstitial();
     }
    
     if (type == "interstitialClosed") {
         show_toast("interstitialClosed");
     }
    
     if (type == "interstitialClicked") {
         // interstitial clicked
         show_toast("interstitialClicked");
     }
    
     if (type == "interstitialFinished") {
         // interstitial finished
         show_toast("interstitialFinished");
     }
    
     if (type == "interstitialShown") {
         show_toast("interstitialShown");
     }
    
    

Native ads

  1. To show a native ad - call create_native("<hash code>")

  2. To receive callbacks - create a SOCIAL event:

    The event receives 2 parameters - 'type' and 'data' (if needed)

     var type = ds_map_find_value(async_load,"type");
    
     if (type == "nativeError") {
         // an error occurred - read the 'data' param to get the cause
         var data = ds_map_find_value(async_load,"data");
         show_toast("nativeError: "+data);
     }
    
     if (type == "nativeReady") {
         // banner loaded successfully
         var data = ds_map_find_value(async_load,"data");
         show_toast("nativeReady: "+data);
    
         // parse data to extract the native ad fields (see below)
     }
    

    The 'nativeReady' event returns the native ad information embedded in a single string. You can use the code below to parse the various fields:

         // parse data returned to get icons, texts, and click URL
         
         var szTitle = "";
         var szBody = "";
         var szIconUrl = "";
         var szMainUrl = "";
         var szClickUrl = "";
         
         var splitBy = "|";
         var splits;
         var slot = 0;
         var str2 = "";
         var i;
         for (i=1;i&lt;string_length(data)+1;i++)
         {
             var currStr = string_copy(data,i,1);
             if (currStr==splitBy)
             {
                 splits[slot] = str2;
                 slot++;
                 str2 = "";
             } else {
                 str2 = str2 + currStr;
                 splits[slot] = str2;
             }
         }
         
         for (i=0;i&lt;=slot;i++)
         {
             var len = string_length(splits[i]);
             
             if (string_length(splits[i])&gt;=10)
             {
                 var cmpWith = string_copy(splits[i],1,10);
                 if (cmpWith=="&lt;Headline&gt;")
                 {
                     szTitle = string_copy(splits[i],11,len-10);
                 }
             }
             
             if (string_length(splits[i])&gt;=13)
             {
                 var cmpWith = string_copy(splits[i],1,13);
                 if (cmpWith=="&lt;Description&gt;")
                 {
                     szBody = string_copy(splits[i],14,len-13);
                 }
             }
             
             if (string_length(splits[i])&gt;=14)
             {
                 var cmpWith = string_copy(splits[i],1,14);
                 if (cmpWith=="&lt;IconImageUrl&gt;")
                 {
                     szIconUrl = string_copy(splits[i],15,len-14);
                 }
             }
             
             if (string_length(splits[i])&gt;=14)
             {
                 var cmpWith = string_copy(splits[i],1,14);
                 if (cmpWith=="&lt;MainImageUrl&gt;")
                 {
                     szMainUrl = string_copy(splits[i],15,len-14);
                 }
             }
             
             if (string_length(splits[i])&gt;=10)
             {
                 var cmpWith = string_copy(splits[i],1,10);
                 if (cmpWith=="&lt;ClickUrl&gt;")
                 {
                     szClickUrl = string_copy(splits[i],11,len-10);
                 }
             }
             
         }
    
         // now use the parsed data to show the native ad:
         
         global.nativeTitle = szTitle;
         global.nativeIcon  = szIconUrl;
         global.nativeMain  = szMainUrl;
         global.nativeBody  = szBody;
         global.nativeClickUrl = szClickUrl;
     }
    
    

    To use the info received, you can - for example - create a 'native_img_icon' and 'native_img_main' objects, and draw the icon and main image in them:

    
         with (native_img_icon)
         {
             sprite_index = sprite_add(global.nativeIcon,1,false,false,0,0);
         }
         
         with (native_img_main)
         {
             sprite_index = sprite_add(global.nativeMain,1,false,false,0,0);
             image_xscale = 0.5;
             image_yscale = 0.5;
         }
    
    

    Create a 'native_img_icon' and 'native_img_main' objects, and draw the icon and main image in them:

         if (string_length(global.nativeTitle)>0)
         {
             draw_set_valign(fa_top);
             draw_set_halign(fa_left);
             draw_text(120,bbox_top,global.nativeTitle);
         }
    
         if (string_length(global.nativeBody)>0)
         {
             draw_set_valign(fa_top);
             draw_set_halign(fa_left);
             draw_text(120,bbox_top+40,global.nativeBody);
         }
    
    

    And when the user taps on the native ad area:

         if (string_length(global.nativeClickUrl)>0)
         {
             url_open(global.nativeClickUrl);
         }
    

Location

  1. To enable/disable use of location info for ads - call set_use_location(1/0)

Clone this wiki locally