screen edge

Hi,

I’m a starter in corona projects, trying to do my first project i had a surprise, the walls was not fit in the screen as it should and as i saw in the videos tutorials and as it is written in the tutorials in the net.

the code that i copied and the results are in the picture attached…

i just doesn´t know why the command rect not fit exactly in the screen edges.
 

What do you have in config.lua?

i have this in config.lua

application = {

content = {

width = 320,

height = 480, 

scale = “letterBox”,

fps = 30,

–[[

        imageSuffix = {

   ["@2x"] = 2,

}

–]]

},

    --[[

    – Push notifications

    notification =

    {

        iphone =

        {

            types =

            {

                “badge”, “sound”, “alert”, “newsstand”

            }

        }

    }

    --]]    

}

Based on the code you have in the screenshot, please try this for the right wall and see if it fixes the problem.  If so, you can apply the same logic to other cases:

Change this:

local rightWall = display.newRect( display.contentWidth - 10, 0, 10, display.contentHeight )

to this:

-- (only subtract half the width) local rightWall = display.newRect( display.contentWidth - 5, 0, 10, display.contentHeight )

This is even better:

local rightWall = display.newRect( display.viewableContentWidth - 5, 0, 10, display.viewableContentHeight )

tried all this ways and didn’t work… 

i had to put the command that way to work:

local topWall = display.newRect( 160,0, display.contentWidth, 10 )

local bottomWall = display.newRect( 160, display.contentHeight , display.contentWidth, 10 )

local leftWall = display.newRect( 0, 240, 10, display.contentHeight )

local rightWall = display.newRect( display.contentWidth, 240, 10, display.contentHeight )

but i want to know what is wrong in my screen… 

thanks for your time

Hi @rubenshcm,

When working with “letterbox” scale, I usually set two variables near the top of my code that I can use to calculate the width/height of the empty bars on any screen aspect ratio:

[lua]

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

[/lua]

Then, I use these elsewhere to adjust items toward one edge of the screen. For example, if you have 100x100 rectangle and you want its top edge to always meet the top edge of the screen, it might look like this:

[lua]

local r1 = display.newRect( 160, 50-oy, 100, 100 )

[/lua]

Or to make a rectangle’s left edge meet the left edge of the screen:

[lua]

local r2 = display.newRect( 50-ox, 240, 100, 100 )

[/lua]

Again, these variable represent the exact number of pixels (width and height) of the letterbox bars on any screen, so you can use them to position objects accordingly.

Hope this helps,

Brent

thanks i get it! 

What do you have in config.lua?

i have this in config.lua

application = {

content = {

width = 320,

height = 480, 

scale = “letterBox”,

fps = 30,

–[[

        imageSuffix = {

   ["@2x"] = 2,

}

–]]

},

    --[[

    – Push notifications

    notification =

    {

        iphone =

        {

            types =

            {

                “badge”, “sound”, “alert”, “newsstand”

            }

        }

    }

    --]]    

}

Based on the code you have in the screenshot, please try this for the right wall and see if it fixes the problem.  If so, you can apply the same logic to other cases:

Change this:

local rightWall = display.newRect( display.contentWidth - 10, 0, 10, display.contentHeight )

to this:

-- (only subtract half the width) local rightWall = display.newRect( display.contentWidth - 5, 0, 10, display.contentHeight )

This is even better:

local rightWall = display.newRect( display.viewableContentWidth - 5, 0, 10, display.viewableContentHeight )

tried all this ways and didn’t work… 

i had to put the command that way to work:

local topWall = display.newRect( 160,0, display.contentWidth, 10 )

local bottomWall = display.newRect( 160, display.contentHeight , display.contentWidth, 10 )

local leftWall = display.newRect( 0, 240, 10, display.contentHeight )

local rightWall = display.newRect( display.contentWidth, 240, 10, display.contentHeight )

but i want to know what is wrong in my screen… 

thanks for your time

Hi @rubenshcm,

When working with “letterbox” scale, I usually set two variables near the top of my code that I can use to calculate the width/height of the empty bars on any screen aspect ratio:

[lua]

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

[/lua]

Then, I use these elsewhere to adjust items toward one edge of the screen. For example, if you have 100x100 rectangle and you want its top edge to always meet the top edge of the screen, it might look like this:

[lua]

local r1 = display.newRect( 160, 50-oy, 100, 100 )

[/lua]

Or to make a rectangle’s left edge meet the left edge of the screen:

[lua]

local r2 = display.newRect( 50-ox, 240, 100, 100 )

[/lua]

Again, these variable represent the exact number of pixels (width and height) of the letterbox bars on any screen, so you can use them to position objects accordingly.

Hope this helps,

Brent

thanks i get it!