local bg = display.newRect(0, 0 ,10, 10) bg.anchorX = display.screenOriginX bg.anchorY = display.screenOriginY bg.width = display.contentWidth bg.height = display.contentHeight
Generally speaking .anchorX/.anchorY should be in the range of 0…1 and it changes the meaning of what .x and .y means. The default of 0.5 and 0.5 represent the center of the rectangle. anchorX = 0 would make .x be on the left edge of the box. anchorX = 1 would make the x reference the right side of the box.
.screenOriginX, .screenOriginY represent the distance between the left, top edges and the 0, 0 location on the screen. Let’s look at this example. I’m going to assume this is a portrait app for purpose of this discussion. Most people define their content area as 320x480 in their config.lua. This creates a virtual content area on your screen that’s 320 points wide and 480 points high. On an iPhone 4, this was a perfect fit and has an aspect ratio of 2:3 or 1:1.5. The screen is 1.5x taller than it is wide… When you use a phone like the iPhone 6 plus, it has an aspect ratio of 9:16 (Aspect ratios are usually listed in horizontal orientation, i.e. 16:9, but since we are staying in portrait mode, I’ll flip them). That means the iPhone 6 Plus is 1.7777778 x taller than it is wide. (16/9). This makes the physical screen area 320 x 570 and your content area of 320x480 will be centered in that content area by default.
This creates two areas of the screen that are outside your virtual 320x480. You will have 45 points in the negative direction and 45 points beyond the bottom side of the box.
The display constants in this scenario will be
display.contentWidth -- The width value you put in config.lua i.e 320 display.contentHeight -- The height you put in config.lua i.e 480 display.screenOriginX -- will be 0 for a portrait app, -45 for landscape app display.screenOriginY -- will be -45 for a portrait app, 0 for landscape. display.actualContentWidth -- 320 display.actualContentHeight -- 570
Note: I’m using 570 and 45. On some phones the are not exactly 16:9, like the iPhone 5 which is 568 and 44 for these values.
So you really can’t use .anchorX and .anchorY like you are trying to. You’re potentially setting the X, Y reference way off screen. What you want to do if you want to have a full screen rectangle that fits every screen is:
local bg = display.newRect( display.contentCenterX, display.contentCenterY, display.actualContentWidth, display.actualContentHeight )
Rob