Content Positioning

Yeah, sorry the documentation has been “coming” for a while. :sweat_smile:

The main properties you’re interested in are:

screen.minX -- left edge of the screen
screen.maxX -- right edge of the screen
screen.minY -- top edge of the screen
screen.maxY -- bottom of the screen
screen.width -- screen width
screen.height -- screen height
screen.centerX -- screen's center on x-axis
screen.centerY -- screen's center on y-axis
screen.diagonal -- the distance from one corner to the opposite corner

If you wanted to position a display object 20 pixels from the top right corner of the screen, it’d go exactly like you just did it, but you’d have to also offset the object as they are anchored by their centre position by default.

local screen = require( "spyric.screen" )

local object = display.newImage( "image.png" )
object.x = screen.safe.maxX - object.width*0.5 - 20
object.y = screen.safe.minY + object.height*0.5 + 20

-- alternatively you could use anchors to position the objects.
local object = display.newImage( "image.png" )
object.x = screen.safe.maxX - 20
object.y = screen.safe.minY + 20
object.anchorX, object.anchorY = 1, 0

Using screen.safe properties will account for the notches. screen properties go to the actual edges and ignore the notches. If a device doesn’t have notches, then these are the same.

One thing to remember is that in Solar2D the y-coordinates are reversed (not sure what the original design idea was). As you go down in the screen, the value of the y-coordinate increases.

1 Like