display.pixelWidth/Height of iPhone 4 doesn't show images at full display.contentWidth/Height

Each iOS device (iPhone 4, 5, 6, 6, Plus) has its own display.pixelWidth and display.pixelHeight

 

In config.lua, I have:

application = { content = { width = 750, height = 1334, },

Any image that is full screen which I am using in the app is 750 x 1334.

When I add it onto the screen using:

display.newImage(nameOfGroup, "ImageName.png",375,667)

The image fills the screen on every device but the iPhone 4.

On the iPhone 4 (both simulator and device), the image is significantly smaller than the size of the screen and centered.

Can anybody account for why this happens or how I may be able to get around it other than creating assets at 640 x 960 and using those with a conditional:

if (display.pixelHeight == 960) then display.newImage(nameOfGroup, "ImageNamePhone4.png",320,480) else     display.newImage(nameOfGroup, "ImageName.png",375,667) end

Thanks so much in advance!

First of all, display.newImage(), the 2nd and 3rd parameters are the X and Y to center the image on. I believe you want to use display.newImageRect() where the 2nd and 3rd parameters are the width and height of the image.

Focus on your defined content area and understand that on the iPhone 4, since you’re using images shaped for the 16:9 shaped iPhones, part of it will get cut off.

rob

I was using a display.newRect() and the same problem was happening.

This change for display.newImageRect() solved my doubt.

Thanks Rob!

First of all, display.newImage(), the 2nd and 3rd parameters are the X and Y to center the image on. I believe you want to use display.newImageRect() where the 2nd and 3rd parameters are the width and height of the image.

Focus on your defined content area and understand that on the iPhone 4, since you’re using images shaped for the 16:9 shaped iPhones, part of it will get cut off.

rob

I was using a display.newRect() and the same problem was happening.

This change for display.newImageRect() solved my doubt.

Thanks Rob!