display.screenOriginX

类型 数字
display.*
版本 发行版 2024.3703
关键词 屏幕,原点,定位
另请参阅 display.screenOriginY
display.safeScreenOriginX
display.getSafeAreaInsets()

概述

返回从实际屏幕左侧到内容区域左侧的 x 距离,以 Corona 内容单位表示。例如,在 "letterbox""zoomEven" 缩放模式下,当前设备屏幕上可能会添加或裁剪区域。这使您可以了解当前设备上添加或删除了多少可见区域。

示例

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