cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.09k stars 7.05k forks source link

Device::getDPI() is not working with iPhone6 Plus #9419

Open zilongshanren opened 9 years ago

zilongshanren commented 9 years ago

The DPI of iPhone6 Plus is 401, but the Device::getDPI() returns 489 which is wrong.

And some UI controls rely on the DPI of device, so we should fix this issue.

zilongshanren commented 9 years ago
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)

#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))

#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
Priority10 commented 6 years ago

@minggo I think that there is some misunderstanding here. iPhone 6 Plus has a 401 PPI. https://support.apple.com/kb/SP706?viewlocale=en_US

It seems that getDPI() returns the correct result. https://www.paintcodeapp.com/news/iphone-6-screens-demystified

I believe that @dumganhar can say more, because he recently worked on the similar problem. https://github.com/cocos2d/cocos2d-x/issues/18463

Can you close this issue if @dumganhar and @zilongshanren do not mind?

minggo commented 6 years ago

May be it is fixed somewhere, can i use simulator to test it? I don't have iPhone 6 Plus.

Priority10 commented 6 years ago

@minggo Honestly, I do not know about Apple emulators. :(

But I meant that if getDPI() returns 489, then it is the correct value, because PPI is not equal to DPI on some devices. Explanation here https://www.paintcodeapp.com/news/iphone-6-screens-demystified .

And since @dumganhar promised (in English forum) to add the getPPI() interface. Then it seems like both (this issue and https://github.com/cocos2d/cocos2d-x/issues/18463) issues will be solved. But I think that he is more familiar with it than me, so I would like to hear his opinion.