Stuck with admob integration

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:

  1.  How do you implement this into a multi-level game?

  2.  Which piece of codes go into the main.lua and which pieces go into each level game file?

Thanks so much in advance!!

-Christian

The only advice I have is that the key looks incorrect, mine are 15-character alphanumeric, and that if you’re showing a native.* view, it might cover the ad on devices.

henrik5,  thanks for your response.  The appID in the code above is not the actual key.  I just X’ed out my real id and want just to show that’s where I put it.

I am not sure about what you meant on the native view.  I am just wondering why when I run the code above on a single main.lua file, it works perfectly fine.  The problem I am having is when I integrate the code into the storyboard templates like this structure…

Main.lua  -->  Splashscreen -->  Mainmenu Screen -->  Select world (4 of them) --> select level (Game

screen)

…it crashed (blanked out screen) the game even if I put the same code only within the main.lua file.  It’s just odd to me.  I don’t know if it’s because it’s interfering with other files which are “required” within the main.lua.  I’ll just have to figure out by turning off each “required” line and see if that’s it.

In any case, thanks very much for your comment.

-Christian

By native.* I mean the notation in the documentation, views like native.showAlert don’t obey the Corona layering of views and so can end up in front of other views, including ads, I suspect. But if you’re not using one of these view types, it’s not relevant. If you do and they cover the place where the banner is, you may need to hide it before triggering the ad.

One idea could be to start a test-project with a few simple scenes that you step through the same way as in the game, and make the banner work in any scene. Then you could lift the working code into you game, maybe.

henrik5,

Ah, thanks for the clarification. :)  Great points. I still have a lot of exploration to do and will take your advise into account.

Thanks much for taking the time!

-Christian

The only advice I have is that the key looks incorrect, mine are 15-character alphanumeric, and that if you’re showing a native.* view, it might cover the ad on devices.

henrik5,  thanks for your response.  The appID in the code above is not the actual key.  I just X’ed out my real id and want just to show that’s where I put it.

I am not sure about what you meant on the native view.  I am just wondering why when I run the code above on a single main.lua file, it works perfectly fine.  The problem I am having is when I integrate the code into the storyboard templates like this structure…

Main.lua  -->  Splashscreen -->  Mainmenu Screen -->  Select world (4 of them) --> select level (Game

screen)

…it crashed (blanked out screen) the game even if I put the same code only within the main.lua file.  It’s just odd to me.  I don’t know if it’s because it’s interfering with other files which are “required” within the main.lua.  I’ll just have to figure out by turning off each “required” line and see if that’s it.

In any case, thanks very much for your comment.

-Christian

By native.* I mean the notation in the documentation, views like native.showAlert don’t obey the Corona layering of views and so can end up in front of other views, including ads, I suspect. But if you’re not using one of these view types, it’s not relevant. If you do and they cover the place where the banner is, you may need to hide it before triggering the ad.

One idea could be to start a test-project with a few simple scenes that you step through the same way as in the game, and make the banner work in any scene. Then you could lift the working code into you game, maybe.

henrik5,

Ah, thanks for the clarification. :)  Great points. I still have a lot of exploration to do and will take your advise into account.

Thanks much for taking the time!

-Christian