display.screenOriginX

Type Number
Library display.*
Revision Release 2024.3703
Keywords screen, origin, positioning
See also display.screenOriginY
display.safeScreenOriginX
display.getSafeAreaInsets()

Overview

Returns the x distance from the left side of the actual screen to the left side of the content area, in Corona content units. For example, in "letterbox" or "zoomEven" scaling modes, there may be added area or cropped area on the current device screen. This lets you find out how much visible area has been added or removed on the current device.

Example

config.lua
application =
{
    content =
    {
        width = 320,
        height = 480,
        scale = "letterbox"
    },
}
main.lua
-- Create a grey background
local background = display.newRect( 0, 0, 320, 480 )
background:setFillColor( 0.5 )

-- Create two squares
local rect1 = display.newRect( 0, 0, 50, 50 )
local rect2 = display.newRect( 0, 0, 50, 50 )
 
-- Place the squares along the top edge; offset the second square with "display.screenOriginX"
rect1.x = 25
rect2.x = 25 + display.screenOriginX  
rect1.y = 25
rect2.y = 150