Monkey Documentation

Class Admob

The admob class provides simple support for the Google Admob advertising system, which allows you to add advertising to your games. More...


Methods:
Functions:

Detailed Discussion

The admob class provides simple support for the Google Admob advertising system, which allows you to add advertising to your games.

To use Admob advertising in your game:

  1. Create an Admob account and add a new site/app for your game. You can create an Admob account at http://www.admob.com
  2. Add the app config setting ADMOB_PUBLISHER_ID to your game. This must be set to your app's Admob 'Publisher ID'. See App config settings.
  3. Import the brl.admob module into your game and use the Admob class to enable and disable ads as required.

Example

#If TARGET<>"android" And TARGET<>"ios"
#Error "Admob is only supported on Android and iOS targets"
#End

#ADMOB_PUBLISHER_ID="ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY"    'from your admob account
#ADMOB_ANDROID_TEST_DEVICE1="F477AABF905E5DB901B57E1F9DDFA037"  'My Nexus 7!
#ADMOB_ANDROID_TEST_DEVICE2="TEST_EMULATOR"

Import mojo
Import brl.admob

Class MyApp Extends App

    Field admob:Admob
    Field layout:=1
    Field enabled:=True
    
    Method OnCreate()
        admob=Admob.GetAdmob()
        admob.ShowAdView 1,layout
        SetUpdateRate 60
    End
    
    Method OnUpdate()
        If MouseHit0 )
            If enabled
                admob.HideAdView
                enabled=False
            Else
                layout+=1
                If layout=7 layout=1
                admob.ShowAdView 1,layout
                enabled=True
            Endif
        End
    End
    
    Method OnRender()
        Cls
        DrawText "Click to toggle ads!",DeviceWidth/2,DeviceHeight/2,.5,.5
    End
    
End

Function Main()
    New MyApp
End


Method Documentation

Method AdViewHeight : Int ()

Returns the height of the ad view, or 0 if the ad view is hidden.

See also AdViewWidth

Method AdViewWidth : Int ()

Returns the width of the ad view, or 0 if the ad view is hidden.

See also AdViewHeight

Method HideAdView : Void ()

Hides the ad view and disables ads

See also ShowAdView

Method ShowAdView : Void ( style:Int=1, layout:Int=2 )

Shows the ad view and enables ads. The style and layout parameters should be one of the following:

StyleMeaning
1Standard banner
2Smart banner portrait
3Smart banner landscape

LayoutMeaning
1Top left
2Top center
3Top right
4Bottom left
5Bottom center
6Bottom right

See also HideAdView


Function Documentation

Function GetAdmob : Admob ()

Get the global Admob object.