I’m still trying to hide or destroy the add in this LUA File on screen change using “ads.hide()” here is the full code:
start.lua:
local showoverlay = function() local options = { effect = "fade", time = 500 } storyboard.showOverlay( "homead", options ) end timer.performWithDelay( 0, showoverlay, 1 )
homead.lua:
local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local provider = "admob" local appID = "ca-app-pub-\*\*\*\*" local ads = require "ads" function scene:createScene( event ) local group = self.view end function scene:enterScene( event ) local group = self.view -- Create a text object to display ad status local screenGroup = self.view local statusText = display.newText( "", 0, 0, native.systemFontBold, 22 ) statusText:setTextColor( 255 ) statusText:setReferencePoint( display.CenterReferencePoint ) statusText.x, statusText.y = display.contentWidth \* 0.5, 160 local showAd -- Set up ad listener. local function adListener( event ) -- event table includes: -- event.provider -- event.isError (e.g. true/false ) 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 statusText:setTextColor( 255, 0, 0 ) statusText.text = "Error Loading Ad" statusText.x = display.contentWidth \* 0.5 local screenGroup = self.view showAd( "banner" ) else --efter add end end -- Initialize the 'ads' library with the provider you wish to use. if appID then ads.init( provider, appID, adListener ) end -------------------------------------------------------------------------------- -- UI -------------------------------------------------------------------------------- -- initial variables local sysModel = system.getInfo("model") local sysEnv = system.getInfo("environment") screenGroup = self.view -- Shows a specific type of ad showAd = function( adType ) local screenGroup = self.view local adX, adY = display.screenOriginX, 400 statusText.text = "" ads.show( adType, { x=adX, y=adY } ) end -- if on simulator, let user know they must build for device if sysEnv == "simulator" then else local screenGroup = self.view -- start with banner ad showAd( "banner" ) end local hideoverlay = function() storyboard.hideOverlay( "fade", 800 ) end function touchScreen1(event) if event.phase == "began" then timer.performWithDelay( 0, hideoverlay, 1 ) end if event.phase == "ended" then end end Runtime:addEventListener("touch", touchScreen1) end function scene:exitScene( event ) local group = self.view Runtime:removeEventListener("touch", touchScreen1) ads.hide() --[[if sysEnv == "simulator" then else ads.hide() end --]] end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) return scene