如何在 admob 横幅和插页式广告之间切换?如果我在第一个场景中加载横幅并在我进入下一个场景并想要加载插页式广告时将其隐藏,它会向我显示横幅。如果我不加载横幅而只加载“插页式广告场景”,它会加载插页式广告
横幅场景:
local provider = "admob"
local appID = "ca-app-pub-****"
local ads = require "ads"
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
local function adListener( event )
local msg = event.response
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
end
end
if appID then
ads.init( provider, appID, adListener )
end
local sysModel = system.getInfo("model")
local sysEnv = system.getInfo("environment")
local screenGroup = self.view
showAd = function( adType )
local screenGroup = self.view
local adX, adY = display.screenOriginX, 400
statusText.text = ""
ads.show( adType, { x=adX, y=adY } )
end
if sysEnv == "simulator" then
else
local screenGroup = self.view
ads.show( "banner", { x=display.screenOriginX, y=400 } )
end
间隙场景:
local provider = "admob"
local appID = "ca-app-pub-***"
local ads = require "ads"
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 )
local msg = event.response
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
end
end
if appID then
ads.init( provider, appID, adListener )
end
showAd = function( adType )
local screenGroup = self.view
local adX, adY = display.screenOriginX, display.screenOriginY
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
ads.show( "interstitial", { x=0, y=0 } )
end