Keeping adMob to the bottom of screen across platform.

Hello all, I’m desperately trying to find the way or code to have the adMob banner display at the bottom of the screen in a way that will work for all platforms and devices.

Right now I’m using:

local adX, adY = display.screenOriginX, display.viewableContentHeight; ads.show("banner",{x=adX,y=adY});

Which works fine for my Galaxy SIII and on my iPhone 4s, but renders the ad too high on my iPhone 5.

Is there a way to make this work without starting to give different location to different specific devices?

Thanks.

Yuval.

Hi @formatc,

Are you using letterbox or zoomEven scale mode? If letterbox, I tend to use “screenOriginY” to get the pixel amount between the top/bottom of the content area and the screen edge, then push whatever object(s) up or down depending on that value. Of course, my content area size is probably different than yours, so the approach might vary a bit, but it’s a useful tactic.

Best regards,

Brent

Well, I do use “letterBox” scale mode, and to tell you the truth, I’m not even sure what zoomEvent mode is…

About your method, screenOriginY will give me the actual y starting point of the screen (which will be -something, right?), then I should add to it the viewableContentHeight to get the bottom point of the screen, right?

But from there, I’m not sure if what I’ll do is enough, does the adMob banner is set in height? does the reference point of the adMob object, when I call it is bottom? center? top? does it not come in different sizes for different screen/devices? I wish the documentation about it would be better and clearer, it’s too bad these attributes are not available to us through the corona API…

Hi @formatc,

Let’s say, for example, that screenOriginY gives you a value like 104. This will completely vary on your content size setup and the device you’re running on, but that’s the purpose. With this value, and your known content size, you could just say something like:

[lua]

adPositionY = 1200+screenOriginY

[/lua]

And that should bump the ad down to same respective “edge of the screen” no matter which device it’s on. You’d need to take into account the height of the ad, of course.

Experiment with this and let me know what you come up with.

Brent

“You’d need to take into account the height of the ad”, that is exactly my “problem”, since I’m not sure at all the high is uniform for all devices, and I can’t get the height dynamically from the object since that information is not available to us, see my problem?

Yeah, this is a complete mess, I’m sorry, but every code I try to have something global that would work across platforms is simply not working in real life, I did create a code that in the simulator works fine for Galaxy SIII, iPhone 4 and iPhone 5, but when I compile my project, on each device it works differently, for some reason, from what I can see, the adMob object have a different reference point for each device and OS version, something that works perfectly on iPhone 4 with iOS 6.1.3, renders too high on iPhone 4 with iOS 7, and the same goes for iPhone 5, the only “stable” platform I’ve seen so far that acts like the simulator is the Galaxy, but that is not enough.

I’m working a small demonstration for you and collecting screen shots from different devices.

I’ve come up with a code that works just fine in simulator both on PC and MAC, and acts differently on the devices, it would seem the adMob object reference on android is top left while on iOS (iPhone 4/4s/5 tested with iOS 6/7) it’s bottom left, so the same code position the ad on android just fine but on iOS it’s too high by double the height of the ad object, of course I can make a special case for iOS, but I’m still not done testing all the combinations (I’m missing iPhone 5 with iOS 6), I’ll post my code and the screenshots as soon as I’m done, should this be a bug report? I didn’t read about this issue anywhere else…

Can you post your config.lua and your code where you’re trying to position the ad?

Thanks

Rob

Sorry Rob, I will post everything on Monday morning, I don’t have my project files with me over the weekend.

Here we go, my config file settings:

content = {         width = 640,         height = 960,          scale = "letterBox",         fps = 60 }

Now this the code I’ve created to simulate an adMob add to be placed at the bottom of the screen, which works fine on all platforms tested (Galaxy S3 {when will we see Galaxy S4 in simulator??}, iPhone 4/5):

local ad\_obj  = nil; mock\_ad = function()     if ad\_obj ~= nil then         ad\_obj:removeSelf();         ad\_obj = nil;     end     ad\_obj = display.newRect(0,0,display.actualContentWidth,89);     ad\_obj:setReferencePoint(display.TopLeftReferencePoint);     local adX, adY = display.screenOriginX, display.screenOriginY+display.actualContentHeight-89;     ad\_obj.x = adX;     ad\_obj.y = adY; end

This code will create a rectangle with the adMob size (for “banner” attribute") and place it at the bottom of the screen no matter what your device is (in simulator and on actual devices).

And these screen shots I’ve attached from different devices would show you what happens when the same location calculation are performed on the different devices, and you can see that on the Galaxy, it’s fine, on the iOS, it look like the reference point for the object is the bottom, not the top:

Galaxy:

GALAXY_S3_AND412.png

iPhone 4S:

IPHONE_4S_IOS7.png

iPhone 5:

IPHONE_5_IOS613.png

Hi @formatc,

Are you using letterbox or zoomEven scale mode? If letterbox, I tend to use “screenOriginY” to get the pixel amount between the top/bottom of the content area and the screen edge, then push whatever object(s) up or down depending on that value. Of course, my content area size is probably different than yours, so the approach might vary a bit, but it’s a useful tactic.

Best regards,

Brent

Well, I do use “letterBox” scale mode, and to tell you the truth, I’m not even sure what zoomEvent mode is…

About your method, screenOriginY will give me the actual y starting point of the screen (which will be -something, right?), then I should add to it the viewableContentHeight to get the bottom point of the screen, right?

But from there, I’m not sure if what I’ll do is enough, does the adMob banner is set in height? does the reference point of the adMob object, when I call it is bottom? center? top? does it not come in different sizes for different screen/devices? I wish the documentation about it would be better and clearer, it’s too bad these attributes are not available to us through the corona API…

Hi @formatc,

Let’s say, for example, that screenOriginY gives you a value like 104. This will completely vary on your content size setup and the device you’re running on, but that’s the purpose. With this value, and your known content size, you could just say something like:

[lua]

adPositionY = 1200+screenOriginY

[/lua]

And that should bump the ad down to same respective “edge of the screen” no matter which device it’s on. You’d need to take into account the height of the ad, of course.

Experiment with this and let me know what you come up with.

Brent

“You’d need to take into account the height of the ad”, that is exactly my “problem”, since I’m not sure at all the high is uniform for all devices, and I can’t get the height dynamically from the object since that information is not available to us, see my problem?

Yeah, this is a complete mess, I’m sorry, but every code I try to have something global that would work across platforms is simply not working in real life, I did create a code that in the simulator works fine for Galaxy SIII, iPhone 4 and iPhone 5, but when I compile my project, on each device it works differently, for some reason, from what I can see, the adMob object have a different reference point for each device and OS version, something that works perfectly on iPhone 4 with iOS 6.1.3, renders too high on iPhone 4 with iOS 7, and the same goes for iPhone 5, the only “stable” platform I’ve seen so far that acts like the simulator is the Galaxy, but that is not enough.

I’m working a small demonstration for you and collecting screen shots from different devices.

I’ve come up with a code that works just fine in simulator both on PC and MAC, and acts differently on the devices, it would seem the adMob object reference on android is top left while on iOS (iPhone 4/4s/5 tested with iOS 6/7) it’s bottom left, so the same code position the ad on android just fine but on iOS it’s too high by double the height of the ad object, of course I can make a special case for iOS, but I’m still not done testing all the combinations (I’m missing iPhone 5 with iOS 6), I’ll post my code and the screenshots as soon as I’m done, should this be a bug report? I didn’t read about this issue anywhere else…

Can you post your config.lua and your code where you’re trying to position the ad?

Thanks

Rob

Sorry Rob, I will post everything on Monday morning, I don’t have my project files with me over the weekend.

Here we go, my config file settings:

content = {         width = 640,         height = 960,          scale = "letterBox",         fps = 60 }

Now this the code I’ve created to simulate an adMob add to be placed at the bottom of the screen, which works fine on all platforms tested (Galaxy S3 {when will we see Galaxy S4 in simulator??}, iPhone 4/5):

local ad\_obj  = nil; mock\_ad = function()     if ad\_obj ~= nil then         ad\_obj:removeSelf();         ad\_obj = nil;     end     ad\_obj = display.newRect(0,0,display.actualContentWidth,89);     ad\_obj:setReferencePoint(display.TopLeftReferencePoint);     local adX, adY = display.screenOriginX, display.screenOriginY+display.actualContentHeight-89;     ad\_obj.x = adX;     ad\_obj.y = adY; end

This code will create a rectangle with the adMob size (for “banner” attribute") and place it at the bottom of the screen no matter what your device is (in simulator and on actual devices).

And these screen shots I’ve attached from different devices would show you what happens when the same location calculation are performed on the different devices, and you can see that on the Galaxy, it’s fine, on the iOS, it look like the reference point for the object is the bottom, not the top:

Galaxy:

GALAXY_S3_AND412.png

iPhone 4S:

IPHONE_4S_IOS7.png

iPhone 5:

IPHONE_5_IOS613.png

Ive been struggling with getting something to stick to the bottom of the screen as well. I havent tested this on actual devices but it works on the simulator. Let me know how it works for you.

-- can be a rectangle or container or anything local dispObj = display.someKindOfNewShape -- set the anchor to top-left dispObj.anchorX = 0 dispObj.anchorY = 0 -- y position... -- contentHeight + absolute value of origin, since it will be negative... minus the height of the object itself (keep in mind the origin of the object is now at top-left) dispObj.y = (display.contentHeight + math.abs(display.screenOriginY)) - dispObj.contentHeight