Hi everyone,
I am still totally a newbie to Corona so this is probably something really simple but I am stumped. I’ve read all the threads about adding admob and I am not getting anywhere after almost two weeks now. I’d really appreciate if someone could give me some pointers.
I am trying to integrate this sample admod codes into a game and it’s not working.
https://github.com/coronalabs/plugins-sample-ads-admob/tree/master
I think these are the only chunks I need:
[lua]
– The name of the ad provider.
local provider = “admob”
– Your application ID
local appID = “ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX”
– Load Corona ‘ads’ library
local ads = require “ads”
local showAd
– Create a text object to display ad status
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
– 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
showAd( “banner” )
else
statusText:setTextColor( 0, 255, 0 )
statusText.text = “Successfully Loaded Ad”
statusText.x = display.contentWidth * 0.5
end
end
– Initialize the ‘ads’ library with the provider you wish to use.
if appID then
ads.init( provider, appID, adListener )
end
– Shows a specific type of ad
showAd = function( adType )
local adX, adY = display.screenOriginX, display.screenOriginY
statusText.text = “”
ads.show( adType, { x=adX, y=adY } )
end
– start with banner ad
showAd( “banner” )
[/lua]
When I tested the codes as is on my Galaxy S2, it ran perfectly fine. I could see actual live ads. When I tried to integrate it into the game, it gave me a blank screen. That’s it. I think I am doing something wrong.
My project uses STORYBOARD templates. Here’s the flow of the game:
Main.lua --> Splashscreen --> Mainmenu Screen --> Select world (4 of them) --> select level (Game
screen)
Here’s what I have in mind:
Two options:
Option 1) Show the banner ad only during game play for each level
Option 2) Show an interstial ad between each level complete (much preferred)
I guess my real questions are:
-
How do you implement this into a multi-level game?
-
Which piece of codes go into the main.lua and which pieces go into each level game file?
Thanks so much in advance!!
-Christian