Image not aligned to the side of the screen

Hi everyone,

got another newbie question :slight_smile:

Why is that this code below doesnt align the image with the side of my screen? There is a gap on just the left side. It happens on corona simulator and on my android phone.

The blank area is available for render, cause when i remove those 2 anchor lines of code, the gap fills with the image. I dont use any plugins.

local background = display.newImageRect(“assets/bg2.jpg”, 2048, 2048)

background.anchorX = 0

background.anchorY = 0

anchorX and anchorY set the point where the display object itself is positioned from, i.e.

local background = display.newImageRect("assets/bg2.jpg", 2048, 2048) background.x = 200 background.anchorX = 0 -- background's left edge is located at x = 200. background.anchorX = 0.5 -- background is horizontally centered at x = 200. background.anchorX = 1 -- background's right edge is located at x = 200.

In your code, you don’t actually give the background a specific x or y coordinate, so the imageRect remains where it was created, i.e. x, y = { 0, 0 }.

Now, depending on your config.lua settings, it is likely that the screen you are developing or testing on is taller than what you’ve set up. This means that the actual x starting position on the screen isn’t 0, but some negative number. You can find these numbers via https://docs.coronalabs.com/api/library/display/screenOriginX.html.

Ok, I get it I think. So i should position all the main groups i use (bg, game, ui) using screen position and then I can forget about this behaviour, is that right?

You might benefit from going through this tutorial: https://coronalabs.com/blog/2018/08/08/understanding-content-scaling-in-corona/

Thanks for the link, it was helpful!

anchorX and anchorY set the point where the display object itself is positioned from, i.e.

local background = display.newImageRect("assets/bg2.jpg", 2048, 2048) background.x = 200 background.anchorX = 0 -- background's left edge is located at x = 200. background.anchorX = 0.5 -- background is horizontally centered at x = 200. background.anchorX = 1 -- background's right edge is located at x = 200.

In your code, you don’t actually give the background a specific x or y coordinate, so the imageRect remains where it was created, i.e. x, y = { 0, 0 }.

Now, depending on your config.lua settings, it is likely that the screen you are developing or testing on is taller than what you’ve set up. This means that the actual x starting position on the screen isn’t 0, but some negative number. You can find these numbers via https://docs.coronalabs.com/api/library/display/screenOriginX.html.

Ok, I get it I think. So i should position all the main groups i use (bg, game, ui) using screen position and then I can forget about this behaviour, is that right?

You might benefit from going through this tutorial: https://coronalabs.com/blog/2018/08/08/understanding-content-scaling-in-corona/

Thanks for the link, it was helpful!