Retrieve device screen size

Obviously, Corona already does this, to implement content scaling, but it's not transparent to the developer. I need to know the screen size of the device and I can't find any method currently to do it. This is a huge oversight!

display.contentWidth gives you the value in the config.lua file which is fine for working with a single coordinate system, but there should also be an option to get the real screen size. Particularly since Corona doesn't support automatic content scaling.

A display.deviceWidth API would fix all those problems, unless I'm missing something on the documentation that lets you do this already.

+1

I think this is essential, especially as there is a problem with the placement of objects in Android.

For example with dynamic scaling, placing an item at contectHeight on Android doesn't place it at the bottom of the screen. I think there is a bug with Android and STILL waiting for Ansca to reply to my email!

I think you should send this request to them so they can add it to the 'to do' list.

Setting the screen size in the config makes sure you are always working with the same consistent pixel dimensions. This makes dynamic scaling pretty hassle-free to most people, but you're not going to get automatic proportional reposition if you don't do your own work.

display.contentWidth returns the true pixel size if you don't set the dimensions in the config. That's the way it's supposed to be. You can't expect it to return a different size when scaling is on. If you want to get the exact size, you'll have to do your own scaling and position based on the screen size, otherwise, just have another set of code for android. It's not that hard to detect whether you're on iOS or Android.

I've tried the 'magic recipe' as discussed here...

http://blog.anscamobile.com/2010/11/content-scaling-made-easy/

So far so good. The background image scales to fill the screen on all devices.

HOWEVER...

I want to place a 'ground' physics object at the bottom of the screen so do this:

1

local borderBottom = display.newRect( 20, display.contentHeight, display.contentWidth, 30 )

On ALL devices EXCEPT Droid it's placed as expected, on Droid it's placed about 100 pixels too high...

Also placing an object at the top of the screen is correct on ALL devices EXCEPT Droid, where it's placed about 100 pixels lower!

Any help you have offer would be greatly appreciated

I think there is a bug here, why is the placement incorrect for JUST Droid?

Because it's not incorrect. droid devices range from iphone size to taller in proportion and you set the config for an iPhone resolution. If you set the resolution in config, it stays true to that proportion.

You want your ground on the bottom? Try setting yAlign = "bottom" in the config, but you'll have the overflow at the top of your screen instead.

So how can I be sure to be able to place an object at the top of the screen AND the bottom of the screen?

There's a workaround to this now using the new APIs display.contentScaleX and display.contentScaleY

I posted how you can use that to get dynamic scaling spritesheets here. Though I only deal with iphone and iphone 4, for Android you'd need to support much more sizes and your build size would probably increase, but it's doable.

http://developer.anscamobile.com/forum/2010/12/08/dynamic-retina-spritesheets-heres-how

I remain unconvinced this isn't a bug. I would like to see Ansca's solution using the 'magic recipe' that allows correct placement of items for ALL devices.

I've yet to see an actual solution (project) that deals with this problem.

views:2052 update:2011/9/18 14:43:09
corona forums © 2003-2011