Inverted actualContentWidth and height values

Hi,

I have a display.newRect defined with width = display.contentWidth and height = display.contentHeight. Now, on some devices this covers the whole screen but on other devices it looks ‘letter box’.

I have several questions regarding this and would like your help.

(i am using corona build 2100; and the ‘ultimate config.lua’ from Rob’s original article; app in landscape mode [no prtrait mode support])

1- since config.lua is the same, why does this happen (display object covering all the screen) on some devices but not others?

2- when i substitute contentWidth with actualContentWidth and contentHeight with actualContentHeight i get inverted values. Examples:

    a- HTC ONE X:

        -contentWidth: [background=‘yellow’]570[/background]

        -contentHeight: 320

        -viewableContentWidth: 570

        -viewableContentHeight: 320

        -actualContentWidth: [background=‘yellow’]320[/background]

        -actualContentHeight: 570

    b- Samsung Galaxy S Duos S7562

        -contentWidth: 512

        -contentHeight: 320

        -viewableContentWidth: 512

        -viewableContentHeight: 320

        -actualContentWidth: 320

        -actualContentHeight: 533

As you can see in the examples, actualContentWidth and actualContentHeight in landscape mode give inverted values. Why is that?

3- using the ultimate config.lua and an app in landscape mode, how can i declare a display.newRect that is guaranteed to cover the whole screen on all devices?

Many thanks for all your help.

Luay

Hi @mazrabul,

I’m not sure if you read the following “follow up” to the Ultimate config.lua tutorial, but this may help explain it better:

http://www.coronalabs.com/blog/2013/09/10/modernizing-the-config-lua/

As for making a full-screen rectangle in all cases, the approach may vary, and it depends on whether you’re using “letterbox” or “zoomEven” mode in the config. Personally, I prefer to use letterbox and gather the “bleed” X and Y using this code:

[lua]

local ox, oy = math.abs(display.screenOriginX), math.abs(display.screenOriginY)

[/lua]

I do this near the top of my main.lua, so I can use the variables down lower whenever I need them. So, with those in memory, I declare a fullscreen rectangle like this:

[lua]

local screenArea = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth+ox+ox, display.contentHeight+oy+oy )

[/lua]

This is not necessarily the only way or the authoritative way, it’s just what I’ve been using for longer than I remember, and it works and makes sense for me. It also gives me the capability to force objects up against a “screen edge” no matter the screen size/ratio, because I have the values in each direction to use for the offsets, either positive or negative.

Hope this helps,

Brent

Thanks @Brent,

May i ask about question 2, why are the values inverted (as if in portrait mode)? Or do actualContentWidth and actualContentHeight only return values as if in portrait mode (so i have to invert them for landscape)?

Hi @mazrabul,

I’m not sure if you read the following “follow up” to the Ultimate config.lua tutorial, but this may help explain it better:

http://www.coronalabs.com/blog/2013/09/10/modernizing-the-config-lua/

As for making a full-screen rectangle in all cases, the approach may vary, and it depends on whether you’re using “letterbox” or “zoomEven” mode in the config. Personally, I prefer to use letterbox and gather the “bleed” X and Y using this code:

[lua]

local ox, oy = math.abs(display.screenOriginX), math.abs(display.screenOriginY)

[/lua]

I do this near the top of my main.lua, so I can use the variables down lower whenever I need them. So, with those in memory, I declare a fullscreen rectangle like this:

[lua]

local screenArea = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth+ox+ox, display.contentHeight+oy+oy )

[/lua]

This is not necessarily the only way or the authoritative way, it’s just what I’ve been using for longer than I remember, and it works and makes sense for me. It also gives me the capability to force objects up against a “screen edge” no matter the screen size/ratio, because I have the values in each direction to use for the offsets, either positive or negative.

Hope this helps,

Brent

Thanks @Brent,

May i ask about question 2, why are the values inverted (as if in portrait mode)? Or do actualContentWidth and actualContentHeight only return values as if in portrait mode (so i have to invert them for landscape)?