为什么锚点在不同的分辨率下会有所不同?

Why do anchor points vary in different resoliutions?

我目前正在尝试将文本放置在屏幕的四个角,但我遇到的问题是,在某些屏幕分辨率(例如 1080*1920)中,锚点不在角上。由于某种原因,x 值相同,但 y 值发生变化,并且不靠近屏幕的一角。这是我在右上角放置一些文本的示例:

local myText = display.newText( "RIGHT", 0, 0, native.systemFont, 16 )
      myText:setFillColor( 0, 0, 0 )
      myText.anchorX = 1
      myText.anchorY = 0
      myText.x = display.contentWidth
      myText.y = 0

我不明白为什么这不适用于所有屏幕分辨率。

这对你有用吗:

-- Top
myText.y = display.screenOriginY;

-- Bottom
myText.y = display.contentHeight - display.screenOriginY;

-- Right
myText.x = display.contentWidth - display.screenOriginX;

-- Left
myText.x = display.screenOriginX;

显示对象的锚点不会改变。

换屏坐标系取决于缩放模式。所以左上角并不总是 (0, 0)。例如在 letterbox 模式下左上角点将是 (display.screenOriginX, display.screenOriginY).

来自科罗纳 documentation

"letterbox" — scales the content area to fill the screen while preserving the same aspect ratio. The entire content area will reside on the screen, but this might result in "black bars" on devices with aspect ratios that differ from your content aspect ratio. Note, however, that you can still utilize this "blank" area and fill it with visual elements by positioning them or extending them outside the content area bounds. Essentially, "letterbox" is an ideal scale mode if you want to ensure that everything in your content area appears within the screen bounds on all devices.

"zoomEven" — scales the content area to fill the screen while preserving the same aspect ratio. Some content may "bleed" off the screen edges on devices with aspect ratios that differ from your content aspect ratio. Basically, "zoomEven" is a good option to ensure that the entire screen is filled by the content area on all devices (and content clipping near the outer edges is acceptable).
  • 信箱

  • 缩放均匀

详细了解 Content Scaling