Implementing AdMob Interstitials

I’m implementing AdMob interstitials, with the main ad code and adlistener in my main.lua

I’m having trouble where on one scene i’m runnning ads.load( “interstitial”, { appId=interstitialAppID, testMode=true } )

and then, on two scenes later I’m running ads.show(“interstitial”) - but when the ad is closed the adlistener seems to fire twice for “shown”…? And I’m using this event listener to load the next scene?

Also, when I only run ads.show, the second time I run the ad and close it, the main game seems to be running twice until it crashes…

I’m running the adverts on their own .lua - so I can simply circumvent them with an inapp purchase.

Should I be considering another way to preload and add interstitials ads - should the ads.load and ads.show be on the same .lua?

I’m not sure why you’re getting two events but you can set a variable that indicates you’re already processed the event.

Perhaps in your main.lua just above your event listener but after you initially require composer:

composer.setVariable( "goingToNewScene", false )

Then in the event listener when you get your shown event:

    local goingToNewScene = composer.getVariable( "goingToNewScene" )     if not goingToNewScene then          composer.setVariable( "goingToNewScene", true )          composer.gotoScene( ... ) -- whatever you're putting in there     end

Then when you get to your scene’s scene:show()'s did phase,

function scene:show( event )     local phase = event.phase     if phase == "did" then         composer.setVariable( "goingToNewScene", false )     end end

Rob

Thanks.

I did some debugging, and I don’t think I’m actually getting more events fired than one.

But, what I did was change the “shown” event for the ads to a scene which doesn’t have timers, and then that scene with a button press goes to the game. That’s solved the problem, but not answered what I was obviously doing wrong?!

I’m not sure why you’re getting two events but you can set a variable that indicates you’re already processed the event.

Perhaps in your main.lua just above your event listener but after you initially require composer:

composer.setVariable( "goingToNewScene", false )

Then in the event listener when you get your shown event:

    local goingToNewScene = composer.getVariable( "goingToNewScene" )     if not goingToNewScene then          composer.setVariable( "goingToNewScene", true )          composer.gotoScene( ... ) -- whatever you're putting in there     end

Then when you get to your scene’s scene:show()'s did phase,

function scene:show( event )     local phase = event.phase     if phase == "did" then         composer.setVariable( "goingToNewScene", false )     end end

Rob

Thanks.

I did some debugging, and I don’t think I’m actually getting more events fired than one.

But, what I did was change the “shown” event for the ads to a scene which doesn’t have timers, and then that scene with a button press goes to the game. That’s solved the problem, but not answered what I was obviously doing wrong?!