Very confused about scaling assets for multiple screens (density independence)

Hi. I am trying to figure out how to stretch interface assets (buttons etc.) so that they consume the same amount of screen space on every Android device. I have read both the official Google guide “Supporting Multiple Screens” (http://developer.android.com/guide/practices/screens_support.html) and the Cocos2d-x guide, “Multi Resolution Support” (http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Multi_resolution_support).

My issue is that it seems the method explained by Cocos2d-x does not take into consideration the screen density (DPI) or physical screen size of the device. So, an asset that appears large enough on a 1024x768 10" tablet will still seem very small on an Android phone that has a similar resolution but much higher DPI. I am trying to achieve the result as shown in Figure 3 on the Google guide.

Am I just not understanding the concept correctly or is it this difficult in Cocos2d-x? All of the multi resolution examples I’ve seen only consider iOS which is very simplistic by comparison to Android devices.

I’m pretty sure what you are asking about is a scheduled feature for the next release.
http://www.cocos2d-x.org/issues/1939

Kevin is right in my opinion because on Android you also have to provide different resources for different densities. A quick solution for you for know may be to make for example 4 directories like “ldpi”, “mdpi”, “hdpi”, “xhdpi” and put all other resources there, according to their target density/resolution. Then, when your app starts you can determine the device density (I think it can be done fairly easy on Java-side, I don’t know about passing a return value back from a JNI call though), and based on it determine the directory prefix for your resource access.

Thanks for the information.

Then, when your app starts you can determine the device density (I think it can be done fairly easy on Java-side, I don’t know about passing a return value back from a JNI call though)

I discovered yesterday that there is already a method available in the latest release to get the DPI from within C++ (getDPI() within the CCDevice class). So, I’m able to use that as a multiplier to manually scale the desired assets based on DPI rather than screen resolution. However, now I’m going mad trying to position a scaled CCMenu (I apply the scale to the CCMenu object itself). If I have a properly positioned CCMenu at 1.0 scale, even scaling it to 1.1 causes the anchor to get out of whack and I can’t figure out exactly what’s happening…

Can you expand a little more on getDPI? I have cocos2d-2.1beta3-x-2.1.1 and I can’t say that I see CCDevice in my project. Do I need to upgrade in order to use it?

Kevin H wrote:

I’m pretty sure what you are asking about is a scheduled feature for the next release.
http://www.cocos2d-x.org/issues/1939

It looks like that issue was closed recently.

Does anyone have any documentation or samples showing how it should work?

With 2.1.3, I used

float scale= CCDevice::getDPI()/160;