Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
[Solved] Is it possible to preload interstitial ads? — Gideros Forum

[Solved] Is it possible to preload interstitial ads?

Tom2012Tom2012 Guru
edited August 2015 in General questions
For example, could you use:

admob:loadAd("interstitial", "xyz")

Early in the app, and then:

admob:showAd()

When you need it to show?

Thanks!

Comments

  • Hello,

    When I make an application, the first thing I do is to load the ads in my main.lua file :

    admob:loadAd("xxx", "xxxx")

    Then I move it if it is a banner :

    admob:setPosition(200, 200)

    In your case you don't need it because the inter take all the screen.

    Then I call :

    admob:showAd()

    In this way, your ad will be loaded and will be ready to be display. But, if the internet connection of the devices isn't good maybe when you will call the showAd() it will be displayed later (maybe few seconds). It could be a problem if the player press "Replay" and the ad will be displayed during the game.

    The Ads plugins has lot of event like :
    AD_RECEIVED
    AD_FAILED
    AD_ACTION_BEGIN
    AD_ACTION_END
    AD_DISMISSED
    AD_DISPLAYED



    Take a look here : http://docs.giderosmobile.com/interface/ads

    Have fun !

  • @Tom2012 yes of course

    basically your loadAd("interstitial") then receive AD_RECEIVED event with type interstitial if ad loaded or AD_FAILED with type interstitial if ad failed to load
    if it loaded you can call showAd("interstitial") to show it
  • Tom2012Tom2012 Guru
    edited August 2015
    Thanks this is starting to make sense.

    So once you call
    admob:loadAd("interstitial", "ca-app-pub-8922743526077835/5905078139")
    Will that ad and key be shown when I call:
    admob:showAd("interstitial")
  • ar2rsawseenar2rsawseen Maintainer
    edited August 2015
    so there are two ways to do that
    1) admob:showAd("interstitial")
    will show interstitial as soon as it is loaded

    2) or preload and show after it was loaded or even later
    admob:loadAd("interstitial")
    admob:adEventListener(Event.AD_RECEIVED, function(e)
    if e.type == "interstitial" then
    --interstitial is loaded
    admob:showAd("interstitial")
    end
    end)
  • Tom2012Tom2012 Guru
    edited August 2015
    Ah that looks good. Checking to see if ad loads is a wise move.

    Here's what I'm using that seems to work well in tests:

    Once, at start of app, in main.lua
    -- Ads plugin
     
    require "ads"
    At the top of each 'scene' (I'm using scene manager)
    	-- setup ad
     
    	admob = Ads.new("admob")
    	admob:setKey("8922743526077835/5905078139")
    	admob:loadAd("interstitial", "ca-app-pub-8922743526077835/5905078139")
    	admob:enableTesting()
     
    	admob:addEventListener(Event.AD_RECEIVED, function() 
    		print("received ad")
    		self.adReceived = true
     
    		admob:addEventListener(Event.AD_ACTION_END, self.changeLevel, self)
    		admob:addEventListener(Event.AD_DISMISSED, self.changeLevel, self)
     
    	end)
     
    	self.admob = admob
    When they tap on a button like 'retry' or 'menu' this function fires:
    function gameOverOutOfTime:showAd()
     
    	fadeToBlack()
     
    	if(self.adReceived) then
     
    		Timer.delayedCall(500, function()
    			admob:showAd("interstitial")
    		end)
     
    	else
     
    		self:changeLevel()
     
    	end
     
    end
  • Looks good, that should work. Assuming the 500ms is the time it takes to fadeToBlack(). :)

    Likes: Tom2012

    My Gideros games: www.totebo.com
    +1 -1 (+1 / -0 )Share on Facebook
  • @totebo - glad you posted! I downloaded your Miner Z app yesterday and I think it's excellent. Very addictive and the art style is great.

    I also like the way you can get a no ads version. I'll work that into my app as it's something I use myself when I buy apps.
  • Thanks! Let me know if you have any questions on implementation.
    My Gideros games: www.totebo.com
Sign In or Register to comment.