2017-09-16 52 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

相關問題