Hi Corona Community,
My name is KC, and I am new to Corona SDK and not too familiar with the API.
Can someone explain the difference between the above three, and possibly an ideal time to use each of them?
Thank you so much in advance!!
KC
Hi Corona Community,
My name is KC, and I am new to Corona SDK and not too familiar with the API.
Can someone explain the difference between the above three, and possibly an ideal time to use each of them?
Thank you so much in advance!!
KC
When you create your config.lua you define a virtual content area that your app will use. In other words you’re defining your own coordinate system sort of. You might define your virtual content area as say: width = 320, height = 480. This is a virtual screen that is 1.5 times taller than it is wide. This is called “Aspect Ratio”. This was the size of the original iPhone/iPhone 3gs family of phones. It has become the standard “content area” for many apps. (BTW: config.lua is always discussed in the context of the device being held vertically.)
When the iPhone 4 came out, it maintained the same aspect ratio, but the screen doubled in pixels. Corona handles this by scaling things accordingly. If you position something at 50, 50 in your content area (based on 320x480), Corona will double it’s size and draw it at 100, 100 is actual pixels. You don’t have to worry about the physical device, you define the content area you want and we take care of the rest.
Moving on, Apple came out with the iPad which is a 4:3 (1.25:1) aspect ratio device compared to the 3:2 (1.5:1) aspect ratio of the iPhone 3/4 families. Then they came out with the iPhone 5 which is a 16:9 (1.777778:1) aspect ratio and Android devices have multiple different aspect ratios. On an iPad, when you use a 320 x 480 content area, the screen is really going to be 360 x 480. If you go to an iPhone 5 or any other 16:9 device, the real screen will be 320 x 570. This is all assuming a “letterbox” scaling mode.
So now to answer your question.
display.contentWidth/display.contentHeight will always return what you put in config.lua (in this example 320 and 480, though these will value will flip based on a vertical app vs. horizontal app.
display.actualWidth/display.actualHeight will display the actual width and height. Using the example above, on an iPad it will return 360 and 480. The iPhone 5 will return 320 and 568 (it’s just a few pixels short of 16:9) Your 320x480 area will typically be centered on the screen. For the iPhone 5, this means that top edge (I’m going to try and keep everything portrait) is actually -44.
between scale modes like letterbox, zoomEven, and the ability to actually create a content area where part of your content area is off screen, display.viewebleContentWidth/display.viewableContentHeight will be the visible area of the screen, while actualContentHeight may represent areas off screen.
Rob
When you create your config.lua you define a virtual content area that your app will use. In other words you’re defining your own coordinate system sort of. You might define your virtual content area as say: width = 320, height = 480. This is a virtual screen that is 1.5 times taller than it is wide. This is called “Aspect Ratio”. This was the size of the original iPhone/iPhone 3gs family of phones. It has become the standard “content area” for many apps. (BTW: config.lua is always discussed in the context of the device being held vertically.)
When the iPhone 4 came out, it maintained the same aspect ratio, but the screen doubled in pixels. Corona handles this by scaling things accordingly. If you position something at 50, 50 in your content area (based on 320x480), Corona will double it’s size and draw it at 100, 100 is actual pixels. You don’t have to worry about the physical device, you define the content area you want and we take care of the rest.
Moving on, Apple came out with the iPad which is a 4:3 (1.25:1) aspect ratio device compared to the 3:2 (1.5:1) aspect ratio of the iPhone 3/4 families. Then they came out with the iPhone 5 which is a 16:9 (1.777778:1) aspect ratio and Android devices have multiple different aspect ratios. On an iPad, when you use a 320 x 480 content area, the screen is really going to be 360 x 480. If you go to an iPhone 5 or any other 16:9 device, the real screen will be 320 x 570. This is all assuming a “letterbox” scaling mode.
So now to answer your question.
display.contentWidth/display.contentHeight will always return what you put in config.lua (in this example 320 and 480, though these will value will flip based on a vertical app vs. horizontal app.
display.actualWidth/display.actualHeight will display the actual width and height. Using the example above, on an iPad it will return 360 and 480. The iPhone 5 will return 320 and 568 (it’s just a few pixels short of 16:9) Your 320x480 area will typically be centered on the screen. For the iPhone 5, this means that top edge (I’m going to try and keep everything portrait) is actually -44.
between scale modes like letterbox, zoomEven, and the ability to actually create a content area where part of your content area is off screen, display.viewebleContentWidth/display.viewableContentHeight will be the visible area of the screen, while actualContentHeight may represent areas off screen.
Rob