2017-09-16 123 views
0

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

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

回答

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; 
+0

如果我想把它放在底部怎么办?这将如何工作? –

+0

@referferferferferf我已经更新了答案。 –

1

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

画面切换的坐标系取决于缩放模式。所以左上角的点不总是(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). 
  • 信箱

enter image description here

  • zoomEven

enter image description here

查看更多about Content Scaling

相关问题