display.pixelWidth, display.pixelHeight different between simulator and device

Can anybody share with me why these values for display.pixelHeight (and pixelWidth) are different?

iPad Air shows as 1536 x 2048 in the simulator.

iPad Mini shows as 768 x 1024 in the simulator.

I have a newer iPad Mini with 1536 x 2048 resolution, display.pixelHeight and Width show as 640 x 960

I have an original iPad Mini with 768 x 1024 resolution, display.pixelHeight and Width show as 320 x 480

Are you talking about the Corona simulator or the iOS Xcode simulator?

If it’s the Corona simulator, just use the iPad Air simulator to represent the iPad Mini 2. They are the same aspect ratio as the iPad Air. One emulates the 768x1024 format (iPad 2, original Mini) while the iPad Air skin covers all the 1536x2048 devices. 

Rob

Thanks for answering, Rob. I am wondering more about why it is that when I run the app on a 768x1024 device and print the display.pixelHeight and display.pixelWidth it shows me 320 x 480.

And when I run the app on a 1536x2048 device and print the display.pixelHeight and display.pixelWidth it shows 640 x 960

Seems like you have a couple of different threads going.

You don’t have a scale set in your config.lua. Normally you would have:

application = { content = { width = 320, height = 480, scale = "letterbox", fps = 60, }, }

where the options to scale are:  “letterbox”, “zoomEven”, or “adaptive”.  “adaptive” doesn’t use width or height and gives you content units based on a 320 point system. Most people use “letterbox”. 

When you don’t specify a scaling mode, you have to do your own, which is extra work. Try adding the “letterbox” scaling and see how that changes things for you.

Rob

I’ve added scale = “letterbox” to config.lua and built the app and am running it on a device (iPad Mini 768 x 1024) and when I get to the print statement display.pixelWidth and display.pixelHeight it still prints 320 and 480.

The answer by remiduchalard in the other thread helped me find code to do what I need at this point, but I was looking to better understand Corona on different devices so I could better find the best way to code visual parts of apps in the future.

Should I even be looking at display.pixelWidth/pixelHeight to try and fit objects on a screen?

Should I be more concerned with display.contentWidth/contentHeight?

Or display.actualContentWidth/actualContentHeight?

print statements for iPad Mini - DEVICE:

pixelWidth/height - 320 x 480

contentWidth/height - 750 x 1334

actualContentWidth/height - 750 x 1334

print statements for iPad Mini - Corona Simulator:

pixelWidth/height - 768 x 1024

contentWidth/height - 750 x 1334

actualContentWidth/height - 750 x 1334

print statements for iPad Mini 2 - DEVICE:

pixelWidth/height - 640 x 960

contentWidth/height - 750 x 1334

actualContentWidth/height - 750 x 1334

print statements for iPad Air - Corona Simulator:

pixelWidth/height - 1536 x 2048

contentWidth/height - 750 x 1334

actualContentWidth/height - 750 x 1334

Thanks…

None of that makes any sense.

contentWidth/Height should return what you set width/height to in config.lua. Lets call these points not pixels since we are going to scale the pixels to make the points work out.

pixelWidth/Height should return the actual pixel width/height of the device – in pixels not points.

actualContentWidth/Height should return to you the actual content height/width in points.

Normally in config.lua most people define a width/height to be 320x480.  This is an aspect ratio of 1.5:1 (or 3:2) which is the shape of the original iPhone 3/4 family and many early Android devices. Today’s phones are typical HDTV shaped (16:9 or 1.77778:1) meaning for portrait app, it’s going to be taller than a 320x480. Your iPads are all a 4:3 aspect ratio meaning they are closer to square than the phones. Again working purely in content points with an iPhone 6, which is physically 750x1334, it becomes a 320x568 when scaled to a config.lua using 320x480. There are 44 pixels above the content area and 44 below (assuming your content area is centered and assuming you’ve chosen letterbox as the scaling method.)  For the iPad, the actual content area will end up being 360 x 480 since the extra space on an iPad relative to a 320x480 content area is on the sides.

I did a simple test with this config.lua:

application = { content = { width = 750, height = 1334, scale = "letterbox", fps = 60, }, }

and this main.lua:

print("contentWidth,height", display.contentWidth, display.contentHeight) print("actualContentWidth,height", display.actualContentWidth, display.actualContentHeight) print("pixelWidth,height", display.pixelWidth, display.pixelHeight)

Here are my results:

Corona Simulator iPhone 6 skin:

Oct 12 11:39:32.236 contentWidth,height 750 1334

                                  actualContentWidth,height 751.54931640625 1334

Oct 12 11:39:32.239 pixelWidth,height 640 1136

iPad mini:

Oct 12 11:40:01.736 contentWidth,height 750 1334

                                  actualContentWidth,height 1000.5 1334

                                  pixelWidth,height 768 1024

iPad Air:

Oct 12 11:40:53.716 contentWidth,height 750 1334

                                  actualContentWidth,height 1000.5 1334

Oct 12 11:40:53.716 pixelWidth,height 1536 2048

Actual iPad 4 (Retina)

Oct 12 11:54:42.654 [Device] contentWidth,height 750 1334

Oct 12 11:54:42.654 [Device] actualContentWidth,height 1000.5 1334

Oct 12 11:54:42.655 [Device] pixelWidth,height 1536 2048

My iPhone 6

Oct 12 11:56:35.902 [Device] contentWidth,height 750 1334

Oct 12 11:56:35.948 [Device] actualContentWidth,height 751.54931640625 1334

Oct 12 11:56:35.949 [Device] pixelWidth,height 640 1136

Here the pixelWidth and height don’t match what it should. In fact its reporting an iPhone 5 screen size. This isn’t a bug. It’s the way iOS works. My temp app doesn’t have the appropriate launch images setup in build.settings. Since I’m missing my Default-667h@2x.png file (and build.settings entries), the phone is assuming correctly I want to run in iPhone 5 emulation mode.

So based on this test things seem to behave correctly.

Hit send too soon… Can you post the code you’re using to print out your values?

Thank you for taking the time to look into this. I’ve figured out the issue now.

In the build dialog, “iPhone only” was chosen. Although this app was intentioned to be iPhone only, there are people who download and run iPhone apps on an iPad. I was trying to make adjustments in the appearance when the app is run on an iPad. It appears that apps built as “iPhone only”, when running on an iPad, return a pixelWidth/pixelHeight of 480/320 or 960/640 depending on the model of iPad. If built as “iPhone + iPad” the correct 1024/768 or 2048/1536 pixelWidth/Height are produced.

Thanks for your help. It is strange to get the 480/320 or 960/640 dimensions when running on an iPad, but at least I understand the cause of the issue here.

Are you talking about the Corona simulator or the iOS Xcode simulator?

If it’s the Corona simulator, just use the iPad Air simulator to represent the iPad Mini 2. They are the same aspect ratio as the iPad Air. One emulates the 768x1024 format (iPad 2, original Mini) while the iPad Air skin covers all the 1536x2048 devices. 

Rob

Thanks for answering, Rob. I am wondering more about why it is that when I run the app on a 768x1024 device and print the display.pixelHeight and display.pixelWidth it shows me 320 x 480.

And when I run the app on a 1536x2048 device and print the display.pixelHeight and display.pixelWidth it shows 640 x 960

Seems like you have a couple of different threads going.

You don’t have a scale set in your config.lua. Normally you would have:

application = { content = { width = 320, height = 480, scale = "letterbox", fps = 60, }, }

where the options to scale are:  “letterbox”, “zoomEven”, or “adaptive”.  “adaptive” doesn’t use width or height and gives you content units based on a 320 point system. Most people use “letterbox”. 

When you don’t specify a scaling mode, you have to do your own, which is extra work. Try adding the “letterbox” scaling and see how that changes things for you.

Rob

I’ve added scale = “letterbox” to config.lua and built the app and am running it on a device (iPad Mini 768 x 1024) and when I get to the print statement display.pixelWidth and display.pixelHeight it still prints 320 and 480.

The answer by remiduchalard in the other thread helped me find code to do what I need at this point, but I was looking to better understand Corona on different devices so I could better find the best way to code visual parts of apps in the future.

Should I even be looking at display.pixelWidth/pixelHeight to try and fit objects on a screen?

Should I be more concerned with display.contentWidth/contentHeight?

Or display.actualContentWidth/actualContentHeight?

print statements for iPad Mini - DEVICE:

pixelWidth/height - 320 x 480

contentWidth/height - 750 x 1334

actualContentWidth/height - 750 x 1334

print statements for iPad Mini - Corona Simulator:

pixelWidth/height - 768 x 1024

contentWidth/height - 750 x 1334

actualContentWidth/height - 750 x 1334

print statements for iPad Mini 2 - DEVICE:

pixelWidth/height - 640 x 960

contentWidth/height - 750 x 1334

actualContentWidth/height - 750 x 1334

print statements for iPad Air - Corona Simulator:

pixelWidth/height - 1536 x 2048

contentWidth/height - 750 x 1334

actualContentWidth/height - 750 x 1334

Thanks…

None of that makes any sense.

contentWidth/Height should return what you set width/height to in config.lua. Lets call these points not pixels since we are going to scale the pixels to make the points work out.

pixelWidth/Height should return the actual pixel width/height of the device – in pixels not points.

actualContentWidth/Height should return to you the actual content height/width in points.

Normally in config.lua most people define a width/height to be 320x480.  This is an aspect ratio of 1.5:1 (or 3:2) which is the shape of the original iPhone 3/4 family and many early Android devices. Today’s phones are typical HDTV shaped (16:9 or 1.77778:1) meaning for portrait app, it’s going to be taller than a 320x480. Your iPads are all a 4:3 aspect ratio meaning they are closer to square than the phones. Again working purely in content points with an iPhone 6, which is physically 750x1334, it becomes a 320x568 when scaled to a config.lua using 320x480. There are 44 pixels above the content area and 44 below (assuming your content area is centered and assuming you’ve chosen letterbox as the scaling method.)  For the iPad, the actual content area will end up being 360 x 480 since the extra space on an iPad relative to a 320x480 content area is on the sides.

I did a simple test with this config.lua:

application = { content = { width = 750, height = 1334, scale = "letterbox", fps = 60, }, }

and this main.lua:

print("contentWidth,height", display.contentWidth, display.contentHeight) print("actualContentWidth,height", display.actualContentWidth, display.actualContentHeight) print("pixelWidth,height", display.pixelWidth, display.pixelHeight)

Here are my results:

Corona Simulator iPhone 6 skin:

Oct 12 11:39:32.236 contentWidth,height 750 1334

                                  actualContentWidth,height 751.54931640625 1334

Oct 12 11:39:32.239 pixelWidth,height 640 1136

iPad mini:

Oct 12 11:40:01.736 contentWidth,height 750 1334

                                  actualContentWidth,height 1000.5 1334

                                  pixelWidth,height 768 1024

iPad Air:

Oct 12 11:40:53.716 contentWidth,height 750 1334

                                  actualContentWidth,height 1000.5 1334

Oct 12 11:40:53.716 pixelWidth,height 1536 2048

Actual iPad 4 (Retina)

Oct 12 11:54:42.654 [Device] contentWidth,height 750 1334

Oct 12 11:54:42.654 [Device] actualContentWidth,height 1000.5 1334

Oct 12 11:54:42.655 [Device] pixelWidth,height 1536 2048

My iPhone 6

Oct 12 11:56:35.902 [Device] contentWidth,height 750 1334

Oct 12 11:56:35.948 [Device] actualContentWidth,height 751.54931640625 1334

Oct 12 11:56:35.949 [Device] pixelWidth,height 640 1136

Here the pixelWidth and height don’t match what it should. In fact its reporting an iPhone 5 screen size. This isn’t a bug. It’s the way iOS works. My temp app doesn’t have the appropriate launch images setup in build.settings. Since I’m missing my Default-667h@2x.png file (and build.settings entries), the phone is assuming correctly I want to run in iPhone 5 emulation mode.

So based on this test things seem to behave correctly.

Hit send too soon… Can you post the code you’re using to print out your values?

Thank you for taking the time to look into this. I’ve figured out the issue now.

In the build dialog, “iPhone only” was chosen. Although this app was intentioned to be iPhone only, there are people who download and run iPhone apps on an iPad. I was trying to make adjustments in the appearance when the app is run on an iPad. It appears that apps built as “iPhone only”, when running on an iPad, return a pixelWidth/pixelHeight of 480/320 or 960/640 depending on the model of iPad. If built as “iPhone + iPad” the correct 1024/768 or 2048/1536 pixelWidth/Height are produced.

Thanks for your help. It is strange to get the 480/320 or 960/640 dimensions when running on an iPad, but at least I understand the cause of the issue here.