So I have the banner ad showing up during the game over / results screen. Normally, it works fine, except when I click ‘restart’ faster than the ad can show up, then the ad shows up in the main game. I was hoping someone could look at my work and see what’s happening.
Restart.lua
local composer = require( "composer" ) local myData = require( "myData" ) local score = require( "score" ) local coronaAds = require( "plugin.coronaAds" ) local scene = composer.newScene() \_W = display.contentWidth; \_H = display.contentHeight local bannerPlacement = "top-banner-320x50" local interstitialPlacement = "interstitial-1" local randomAd = math.random(1,10) audio.setVolume( 0.5, { channel = 1 } ) -- Sound Effects Channel Volume audio.setVolume( 0.4, { channel = 2 } ) -- Sound Track Channel Volume -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- local function showAd() if randomAd == 10 then coronaAds.hide() coronaAds.show(interstitialPlacement, true) else coronaAds.hide() coronaAds.show(bannerPlacement, false) end end local function adListener(event) if (event.phase == "init") then showAd() end end local function start(event) if event.phase == "ended" then audio.play(menuSelect, {channel = 1}) saveScore() composer.gotoScene("mainGame", "fade", 500) end end local function titleScreen(event) if event.phase == "ended" then audio.play(menuSelect, {channel = 1}) saveScore() composer.gotoScene("start", "fade", 500) end end function showStart() scoreTransition = transition.to(backPanel2,{time=600, alpha = 0.5,}) restartTransition = transition.to(restartButton,{time=600, alpha = 1}) endButtonTransition = transition.to(endButton,{time=600, alpha = 1}) scoreTextTransition = transition.to(scoreText,{time=600, alpha = 1}) scoreTextTransition2 = transition.to(bestText,{time=600, alpha = 1}) scoreTextTransition3 = transition.to(boardText1,{time=600, alpha = 1}) scoreTextTransition4 = transition.to(boardText2,{time=600, alpha = 1}) scoreTextTransition5 = transition.to(optionsText,{time=600, alpha = 1}) print("Restart myData: " .. myData.score) end --[[function showScore() end function showGameOver() fadeTransition = transition.to(backPanel,{time=600, y=\_H \* 0.6 ,onComplete=showScore}) end]] function loadScore() local prevScore = score.load() if prevScore ~= nil then if prevScore \<= myData.score then score.set(myData.score) else score.set(prevScore) end else score.set(myData.score) end end function saveScore() score.save() end -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- -- create() function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen local background = display.newImage("layer-1.png") background.anchorX = 0; background.anchorY = 0 background.x = 0; background.y = 0 background.width = display.contentWidth; background.height = display.contentHeight + 70 ------------------ Dead Bird Animation----------- --||||||||||||||| Bird |||||||||||||||||||||||||| local sheetOptions1 ={width = 561,height = 435,numFrames = 4} local sheet\_idleBird = graphics.newImageSheet( "deadBird.png", sheetOptions1 ) local sequences\_idleBird = {{name = "normalFly",start = 1,count = 4,time = 800,loopCount = 0,},} deadBird = display.newSprite(sheet\_idleBird, sequences\_idleBird) deadBird.x = 220; deadBird.y = 150; deadBird:scale(0.5,0.5) backPanel2 = display.newImageRect("yellow\_panel.png", 270, 190) backPanel2.x = \_W \* 0.5; backPanel2.y = \_H \* 0.6; backPanel2.alpha = 0; restartButton = display.newImageRect("blue\_button00.png", 135, 40) restartButton.x = \_W \* 0.36; restartButton.y = \_H \* 0.835; restartButton.alpha = 0; endButton = display.newImageRect("green\_button00.png", 135, 40) endButton.x = \_W \* 0.64; endButton.y = \_H \* 0.835; endButton.alpha = 0; scoreText = display.newText(myData.score, \_W\*0.75,\_H \* 0.45, "Impact", 50) scoreText.alpha = 0; scoreText.anchorX = 1; bestText = score.init({fontSize = 50,font = "Impact",x = \_W\*0.75,y = \_H \* 0.67, maxDigits = 7,leadingZeros = false,filename = "scorefile.txt",}) bestText.alpha = 0; bestText.anchorX = 1; bestScore = score.get() bestText.text = bestScore boardText1 = display.newText("SCORE", \_W\*0.25, \_H \* 0.45, "Impact", 50) boardText1.anchorX = 0; boardText1.anchorX = 0; boardText2 = display.newText("BEST", \_W\*0.25, \_H \* 0.67, "Impact", 50) boardText2.anchorX = 0; boardText2.anchorX = 0; optionsText = display.newText("RESTART END", \_W\*0.45, \_H \* 0.835, "Impact", 30) boardText1.alpha = 0; boardText2.alpha = 0; optionsText.alpha = 0; menuSelect = audio.loadSound("menuSelect.mp3") restartSound = audio.loadStream("funkyRooster.mp3") sceneGroup:insert(background) sceneGroup:insert(deadBird) sceneGroup:insert(backPanel2) sceneGroup:insert(restartButton) sceneGroup:insert(endButton) sceneGroup:insert(scoreText) sceneGroup:insert(bestText) sceneGroup:insert(boardText1) sceneGroup:insert(boardText2) sceneGroup:insert(optionsText) coronaAds.init("5223c2c3-cf81-4c43-ae41-2d4ed16552bc", adListener) end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) --audio.fade( { channel=2, time=400, volume=0.8 } ) -- Sound Track Channel Volume elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen print("Restart - Show - should see this once.") deadBird:play() composer.removeScene("mainGame") restartButton:addEventListener("touch", start) endButton:addEventListener("touch", titleScreen) audio.play(restartSound, {channel = 2, loops = -1}) showStart() loadScore() showAd() end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) --audio.fadeOut( { channel=2, time=1000 } ) coronaAds.hide() elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen restartButton:removeEventListener("touch", start) endButton:removeEventListener("touch", titleScreen) transition.cancel(fadeTransition) transition.cancel(scoreTransition) transition.cancel(scoreTextTransition) transition.cancel(scoreTextTransition2) transition.cancel(restartTransition) transition.cancel(endButtonTransition) end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view audio.stop(1) audio.stop(2) audio.dispose(menuSelect) audio.dispose(restartSound) menuSelect = nil restartSound = nil end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene