为什么不同的resoliutions锚点会有所不同?

时间:2017-09-16 19:38:26

标签: lua corona

我目前正试图在屏幕的四个角落放置文字,但我遇到的是在一些屏幕分辨率(例如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

我无法理解为什么这对所有屏幕分辨率都不起作用。

2 个答案:

答案 0 :(得分:1)

这对你有用吗?

-- Top
myText.y = display.screenOriginY;

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

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

-- Left
myText.x = display.screenOriginX;

答案 1 :(得分:1)

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

屏幕更改的坐标系取决于缩放模式。所以左上角并不总是(0, 0)。例如,在letterbox模式中,左上角点为(display.screenOriginX, display.screenOriginY)

来自Corona 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).
  • 信箱

enter image description here

  • zoomEven

enter image description here

详细了解Content Scaling