How To Position An Ad On The Center Of The Screen

Hey guys, Im trying to position an inmobi ad in the center of the screen across multiple devices and I’m struggling with it.

I was using:

local adType = “banner320x48”

local adWidth = 320

local adHeight = 48

adWidth = adWidth * display.contentScaleX

adHeight = adHeight * display.contentScaleY

ads.show( adType, { x=screenW*0.5 - adWidth*0.5, y=screenH-adHeight, interval=5, testMode=true } )

And I thought it was ok since I tested in iPad 2, Galaxy Ace Plus and Galaxy Tab, but once I tested in my Samsung SII this positioning method failed.

I guess it’s worth mentioning I’m using “The ultimate config.lua” by Rob (http://www.coronalabs.com/blog/2012/12/04/the-ultimate-config-lua-file/)

Thanks!

I just tried this code:

local adType = “banner320x48”

local adWidth = 320

local adHeight = 48

if display.pixelWidth >= 728 then 

    adType = “banner728x90”

    adWidth = 728

    adHeight = 90

end

local adX = (screenW*0.5) - (adWidth*0.5)

local adY = screenH - adHeight

ads.show( adType, { x=adX, y=adY, interval=5, testMode=true } )

And it works in my Samsung S2, but breaks the positioning in my iPad…

I wonder if there’s a code that’ll fix it entirely

I’ve found that the inMobi positioning does appear to be off.  It seems to me that 728x90 banners render in actual physical pixels (or double pixels on an iPad 3), rather than in Corona content pixels (which depend on your config.lua settings).  In my case, the factor that the positioning and size is off is 1.0667 (which is 1024/960, related to the iPad physical dimension vs. my config.lua assumed dimension).

  • Andrew

I’m getting crazy over this issue…
How can I align my ads at the bottom and center of my screen flawlessly?

I tried to use inneractive, but positioning those ads seem completely random.

local adY = display.contentHeight - 66
ads.show( “banner”, { x=0, y=adY, interval=60, adListener } )

Positioned a banner at the correct location on an iPhone and on the middle and left of the screen on my iPad… it doesn’t make any sense to me…

Shouldn’t that adListener retrieve width or something?

Hey guys,

should I simply give up of centrally positioning my ad on the bottom or is there a solution I haven’t tried?

I just tried this code:

local adType = “banner320x48”

local adWidth = 320

local adHeight = 48

if display.pixelWidth >= 728 then 

    adType = “banner728x90”

    adWidth = 728

    adHeight = 90

end

local adX = (screenW*0.5) - (adWidth*0.5)

local adY = screenH - adHeight

ads.show( adType, { x=adX, y=adY, interval=5, testMode=true } )

And it works in my Samsung S2, but breaks the positioning in my iPad…

I wonder if there’s a code that’ll fix it entirely

I’ve found that the inMobi positioning does appear to be off.  It seems to me that 728x90 banners render in actual physical pixels (or double pixels on an iPad 3), rather than in Corona content pixels (which depend on your config.lua settings).  In my case, the factor that the positioning and size is off is 1.0667 (which is 1024/960, related to the iPad physical dimension vs. my config.lua assumed dimension).

  • Andrew

I’m getting crazy over this issue…
How can I align my ads at the bottom and center of my screen flawlessly?

I tried to use inneractive, but positioning those ads seem completely random.

local adY = display.contentHeight - 66
ads.show( “banner”, { x=0, y=adY, interval=60, adListener } )

Positioned a banner at the correct location on an iPhone and on the middle and left of the screen on my iPad… it doesn’t make any sense to me…

Shouldn’t that adListener retrieve width or something?

Hey guys,

should I simply give up of centrally positioning my ad on the bottom or is there a solution I haven’t tried?

I think this should work to position on top center of screen, or bottom center (see commented line), the variables will calculate the height and width of real pixels of the device you are running.

height_device=math.round(display.contentHeight*(1/display.contentScaleY))

width_device=math.round(display.contentWidth*(1/display.contentScaleX))

if width_device >= 728 then 

    adType = “banner728x90”

    adX=(width_device-728)/2

    adY=0  --change to (adY=height_device-90) for position botton center

else

    adType = “banner320x48”

    adX=(width_device-320)/2

    adY=0 --change to (adY=height_device-48) for position botton center

end

ads.show( adType, { x=adX, y=adY, interval=5, testMode=true } )

Good day!

I think this should work to position on top center of screen, or bottom center (see commented line), the variables will calculate the height and width of real pixels of the device you are running.

height_device=math.round(display.contentHeight*(1/display.contentScaleY))

width_device=math.round(display.contentWidth*(1/display.contentScaleX))

if width_device >= 728 then 

    adType = “banner728x90”

    adX=(width_device-728)/2

    adY=0  --change to (adY=height_device-90) for position botton center

else

    adType = “banner320x48”

    adX=(width_device-320)/2

    adY=0 --change to (adY=height_device-48) for position botton center

end

ads.show( adType, { x=adX, y=adY, interval=5, testMode=true } )

Good day!