Admob code

Hey Guys,

Does anybody know how can I play an interstitial after on game is over and there is a natural break in the game.

This is my main.lua code:

local admob = require( “plugin.admob” )

– AdMob listener function
local function adListener( event )

if ( event.phase == "init" ) then  -- Successful initialization
    -- Load an AdMob interstitial ad
    admob.load( "interstitial", { adUnitId="********" } )
end

end

– Initialize the AdMob plugin
admob.init( adListener, { appId= “*****”, testMode=true } )

if ( admob.isLoaded( “interstitial” ) ) then
admob.show( “interstitial” )
end

admob = require( “plugin.admob” )

– Declare variable for storing banner height; this may change if device is rotated
local bannerHeight

– AdMob listener function
function adListener( event )

if ( event.phase == "init" ) then  -- Successful initialization
    -- Load an AdMob banner ad
    admob.load( "banner", { adUnitId="*******" } )
     
elseif ( event.phase == "loaded" ) then
    if ( event.type == "banner" ) then  -- Banner ad is loaded
        bannerHeight = admob.height()  -- Get the loaded banner's height
        -- Show the banner ad with a 30 pixel gap between the screen bottom
        admob.show( "banner", { y = display.actualContentHeight - bannerHeight - 30 } )
    end
end

end

– Initialize the AdMob plugin
admob.init( adListener, { appId="***********", testMode=true} )

Thank you!!!

Can somebody answer please

If you correctly format the code by putting three ticks or 3 spaces before the paragraph I will help.

1 Like