Search code examples
luacoronasdk

Why do anchor points vary in different resoliutions?


I'm currently trying to place text in the four corners of the screen but the thing I came across was that in some screen resolutions(e.g. 1080*1920) the anchor points aren't right in the corner. the x values for some reason are the same, but the y changes, and is not close to the corner of the screen. Here is an example of me placing some text in the top right corner:

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

I can't understand why this doesn't work for all screen resolutions.


Solution

  • Will this work for you:

    -- Top
    myText.y = display.screenOriginY;
    
    -- Bottom
    myText.y = display.contentHeight - display.screenOriginY;
    
    -- Right
    myText.x = display.contentWidth - display.screenOriginX;
    
    -- Left
    myText.x = display.screenOriginX;