2

I want to know if cocos2d-x support android's XHDPI mode and if yes, how to do that?

2 Answers 2

0

Yes you can do that. For that you'll have to write a native function which will return you the dpi of the device. Accordingly you can then set the directory for resources. Here is the native code in java which will return you the the dpi of screen.

Write this code in Cocos2dxActivity (library file for cocos2d-x android)

static int dpiValue;
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
dpiValue = dm.densityDpi;

public static int deviceDPI()
{
    return dpiValue;
}

Now in your AppDelegate.cpp you can get this value and set the resource folder accordingly

Here is the example code for that

//getting dpi in case of android
JniMethodInfo t;
JniHelper::getStaticMethodInfo(t
        , "org/cocos2dx/lib/Cocos2dxActivity" 
        , "deviceDPI" 
        , "()I");
        int deviceDPI = t.env->CallIntMethod(t.classID, t.methodID, NULL);
CCLog("DPI of screen is %d", deviceDPI);
if(deviceDPI <= 120)
{
    //ldpi
}
else if(deviceDPI <= 160)
{
    //mdpi
}
else if(deviceDPI <= 240)
{
    //mdpi
}
else
{
    //xhdpi
}

Hope this helps you!! :)

0

You can simply use the function CCDevice::getDPI()

If that doesn't help you, you should read this one carefully, it really helped me a lot.

Hope it helps you too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.