Admob V2 interstitial between scenes

Hi I am new here, I have followed the tutorial to put admob ads v2 in my game, but I only understand the method to put banners, and worked fine, I can’t understand how to implement interstitial ads between scenes, how to load, how to control when they will appears, where I need to put the function to load the ads… Can you help me? I tryed to adapt the sample for admob v1 to my game but I can’t, there is another tutorial for admob V2 or sample for interstitial ads?

Hi @boss72,

This tutorial should help you get started on this:

http://coronalabs.com/blog/2014/07/15/tutorial-implementing-admob-v2/

Best regards,

Brent

Hi Brent thank you very much, I have already read this tutorial, but I can’t understand everything. But reading again, this make sense, I can’t thest now but, for example I am using storyboard template, I have to call ads.show() on create scene, or before in my function to change scene? 

There are a couple of ways I would do this. 

First have a dedicated scene just for the interstitial.  Show the ad in the enterScene() function.  When you detect the ad has closed, you can then call gotoScene() to go to your next scene.

Second, since the interstitial shows on top of any display objects, you could go ahead and do it in any enterScene() that you want.  When the ad closes your scene will be there waiting on you.  When you detect the ad closing you can then start any timers, transitions, etc.

Rob

I have been through the tutorial and also have some questions… are there any other explanations?  Especially for the “Detecting When an Interstitial Closes” section??? I would love some more details on this if anyone has done it.

It’s all in this tutorial:

http://coronalabs.com/blog/2014/07/15/tutorial-implementing-admob-v2/

Rob

RIght, that tutorial has been very helpful.  I am stuck on an issue of my ads loading after the next scene has been displayed (sometimes, not always), even when I call the adShow in the scene:Create.  I would like to be able to ‘pause’ the scene until the ad has been shown and closed, but I can’t figure out how to build the ‘pause’ into the adListener and scene.

I am right now playing with a while loop, but it doesn’t feel right and - obviously - doesn’t work…  any thoughts?  The tutorial is great, but I don’t quite understand  how to detect the closing of the interstitial. 

if ( adsLib:isLoaded("interstitial") ) then adsLib:showAd( "interstitial", nil ) DATA.counterforad = 1 local i = 1 while a[i] do if adshown == true then break else timer.performWithDelay( 100, timerListener2 ) i = i + 1 end --print ("wait for ad to close") end else adsLib:loadAd( "interstitial" ) end

and from the adListener function:

local adshown = false --=================================Ad listener============================================ --This listener is for Ads function adListener( event ) local msg = event.response -- just a quick debug message to check what response we got from the library --print("Message received from the ads library: ", msg) if ( event.isError ) then   -- attempt to fetch another ad   print("---------------------ad error----------------------") elseif ( event.phase == "loaded" ) then   -- an ad was preloaded   print("---------------------ad is loaded and ready----------------------")   adshown = false elseif ( event.phase == "shown" ) then   -- the ad was viewed and closed   print("---------------------ad shown----------------------")   adshown = true end end

I don’t know what this adsLib is. 

You could start a timer in your enterScene that checks every second or so to see if a flag has been set, perhaps in some variable that can be accessed from all modules.  In your listener function, you can set a flag that the ad has closed.  When your timer sees the ad has closed then you can start up your level.

Rob

Thank you very much Rob, now with the dedicated scene for instersitial ads my game is much better. Your advices helped me a lot, now I just need to improve my function to detect when the ad is closed.

Hi again, I am still figuring this one out.  I can get the interstitial ad to show, and it now shows without a delay (before any part of the next scene loads) by using a scene just for the ad in between the scenes…  My issue now is where to put the code in tha adscene so that on closing the ad, the next scene is shown.  Right now, closing the ad makes the app go back to the splash screen…

Here is my current adScene code 

gotoscoreScreen = function () local options = { effect = "fromRight", time = 800, params ={screen="playerDataScreen"} } --change scene composer.gotoScene("scoreScreen", options ) end adshowncheck = function() if adshown == true then adtimer.cancel() end end -- ------------------------------------------------------------------------------- -- "scene:create()" function scene:create( event ) local sceneGroup = self.view -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. --print ("wait for ad to close") --timer.performWithDelay(1000,timerpause) end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). adsLib:showAd( "interstitial", nil ) DATA.counterforad = 1 elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. composer.removeHidden() --loop until ad is set as 'shown' adtimer = timer.performWithDelay(200,adshowncheck,0) gotoscoreScreen() end end

and the adlistener from the AdsLib (where all of the ads.* are eventually called)

local adshown = false   --=================================Ad listener============================================ --This listener is for Ads  function adListener( event ) local msg = event.response   -- just a quick debug message to check what response we got from the library --print("Message received from the ads library: ", msg)       if ( event.isError ) then         -- attempt to fetch another ad         print("---------------------ad error----------------------")     elseif ( event.phase == "loaded" ) then         -- an ad was preloaded         print("---------------------ad is loaded and ready----------------------")         adshown = false     elseif ( event.phase == "shown" ) then         -- the ad was viewed and closed         print("---------------------ad shown----------------------")         adshown = true     end end

Any suggestions are greatly appreciated!

bump - bumptiy bump bump

Hi @boss72,

This tutorial should help you get started on this:

http://coronalabs.com/blog/2014/07/15/tutorial-implementing-admob-v2/

Best regards,

Brent

Hi Brent thank you very much, I have already read this tutorial, but I can’t understand everything. But reading again, this make sense, I can’t thest now but, for example I am using storyboard template, I have to call ads.show() on create scene, or before in my function to change scene? 

There are a couple of ways I would do this. 

First have a dedicated scene just for the interstitial.  Show the ad in the enterScene() function.  When you detect the ad has closed, you can then call gotoScene() to go to your next scene.

Second, since the interstitial shows on top of any display objects, you could go ahead and do it in any enterScene() that you want.  When the ad closes your scene will be there waiting on you.  When you detect the ad closing you can then start any timers, transitions, etc.

Rob

I have been through the tutorial and also have some questions… are there any other explanations?  Especially for the “Detecting When an Interstitial Closes” section??? I would love some more details on this if anyone has done it.

It’s all in this tutorial:

http://coronalabs.com/blog/2014/07/15/tutorial-implementing-admob-v2/

Rob

RIght, that tutorial has been very helpful.  I am stuck on an issue of my ads loading after the next scene has been displayed (sometimes, not always), even when I call the adShow in the scene:Create.  I would like to be able to ‘pause’ the scene until the ad has been shown and closed, but I can’t figure out how to build the ‘pause’ into the adListener and scene.

I am right now playing with a while loop, but it doesn’t feel right and - obviously - doesn’t work…  any thoughts?  The tutorial is great, but I don’t quite understand  how to detect the closing of the interstitial. 

if ( adsLib:isLoaded("interstitial") ) then adsLib:showAd( "interstitial", nil ) DATA.counterforad = 1 local i = 1 while a[i] do if adshown == true then break else timer.performWithDelay( 100, timerListener2 ) i = i + 1 end --print ("wait for ad to close") end else adsLib:loadAd( "interstitial" ) end

and from the adListener function:

local adshown = false --=================================Ad listener============================================ --This listener is for Ads function adListener( event ) local msg = event.response -- just a quick debug message to check what response we got from the library --print("Message received from the ads library: ", msg) if ( event.isError ) then   -- attempt to fetch another ad   print("---------------------ad error----------------------") elseif ( event.phase == "loaded" ) then   -- an ad was preloaded   print("---------------------ad is loaded and ready----------------------")   adshown = false elseif ( event.phase == "shown" ) then   -- the ad was viewed and closed   print("---------------------ad shown----------------------")   adshown = true end end

I don’t know what this adsLib is. 

You could start a timer in your enterScene that checks every second or so to see if a flag has been set, perhaps in some variable that can be accessed from all modules.  In your listener function, you can set a flag that the ad has closed.  When your timer sees the ad has closed then you can start up your level.

Rob

Thank you very much Rob, now with the dedicated scene for instersitial ads my game is much better. Your advices helped me a lot, now I just need to improve my function to detect when the ad is closed.

Hi again, I am still figuring this one out.  I can get the interstitial ad to show, and it now shows without a delay (before any part of the next scene loads) by using a scene just for the ad in between the scenes…  My issue now is where to put the code in tha adscene so that on closing the ad, the next scene is shown.  Right now, closing the ad makes the app go back to the splash screen…

Here is my current adScene code 

gotoscoreScreen = function () local options = { effect = "fromRight", time = 800, params ={screen="playerDataScreen"} } --change scene composer.gotoScene("scoreScreen", options ) end adshowncheck = function() if adshown == true then adtimer.cancel() end end -- ------------------------------------------------------------------------------- -- "scene:create()" function scene:create( event ) local sceneGroup = self.view -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. --print ("wait for ad to close") --timer.performWithDelay(1000,timerpause) end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). adsLib:showAd( "interstitial", nil ) DATA.counterforad = 1 elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. composer.removeHidden() --loop until ad is set as 'shown' adtimer = timer.performWithDelay(200,adshowncheck,0) gotoscoreScreen() end end

and the adlistener from the AdsLib (where all of the ads.* are eventually called)

local adshown = false   --=================================Ad listener============================================ --This listener is for Ads  function adListener( event ) local msg = event.response   -- just a quick debug message to check what response we got from the library --print("Message received from the ads library: ", msg)       if ( event.isError ) then         -- attempt to fetch another ad         print("---------------------ad error----------------------")     elseif ( event.phase == "loaded" ) then         -- an ad was preloaded         print("---------------------ad is loaded and ready----------------------")         adshown = false     elseif ( event.phase == "shown" ) then         -- the ad was viewed and closed         print("---------------------ad shown----------------------")         adshown = true     end end

Any suggestions are greatly appreciated!