Can you believe we are still using Cocos2d-iPhone?
Does anyone have a fix for making it work with the newest iPad's and iPhone X's?
Our mode is landscape.
In CCConfiguration.m file updated below function. In this we are handling contentScaleFactor 3.
-(NSInteger) runningDevice
{
NSInteger ret=-1;
#ifdef __CC_PLATFORM_IOS
if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
ret = (CC_CONTENT_SCALE_FACTOR() == 2) ? kCCDeviceiPadRetinaDisplay : kCCDeviceiPad;
}
else if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone )
{
// From http://stackoverflow.com/a/12535566
BOOL isiPhone5 = CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136));
if( CC_CONTENT_SCALE_FACTOR() == 2 ) {
ret = isiPhone5 ? kCCDeviceiPhone5RetinaDisplay : kCCDeviceiPhoneRetinaDisplay;
// Guru - Handle iPhone Plus device, iPhoneX
// - - - - - - - -- -- - - - -- - - - - -
if([[UIScreen mainScreen] scale]==3)
{
ret = kCCDeviceiPhone5RetinaDisplay;
}
}
else
{
// Guru - Handle iPhone Plus device, iPhoneX
// - - - - - - - -- -- - - - -- - - - - -
if([[UIScreen mainScreen] scale]==3)
{
ret = kCCDeviceiPhone5RetinaDisplay;
}
else
// - - - - - - - -- -- - - - -- - - - - -
ret = isiPhone5 ? kCCDeviceiPhone5 : kCCDeviceiPhone;
}
}
#elif defined(__CC_PLATFORM_MAC)
// XXX: Add here support for Mac Retina Display
ret = kCCDeviceMac;
#endif // __CC_PLATFORM_MAC
return ret;
}
Use buttons and other image from iPhone5HD and manually load background for iPhone X
CCSprite *bg ;
if([App isIphoneX])
{
bg = [CCSprite spriteWithFile:@“Background-iphoneX.png"]; // 1624X750 image size
}
else
{
bg = [CCSprite spriteWithFile:@"Background.png"]; // make sure -hd,-ipad,-ipadhd, -iphone5hd there
}
OR just scale bg image
#define SW ([[CCDirector sharedDirector] winSize].width)
#define SH ([[CCDirector sharedDirector] winSize].height)
CCSprite *bg ;
if([App isIphoneX])
{
bg = [CCSprite spriteWithFile:@"Background.png"];
bg.scaleX = SW/bg.contentSize.width;
bg.scaleY = SH/bg.contentSize.height;
}
App Delegate Code:
-(bool)isIphoneX
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
if (screenSize.width == 812) // portrait height = 812
{
return true;
}
if([self isIphoneXR]) // Now in this game iPhoneXR, iPhoneXS Max = iPhoneX,
{
return true;
}
}
return false;
}
-(bool)isIphoneXR
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
if (screenSize.width == 896 && screenSize.height == 414)
{
return true;
}
}
return false;
}
NOTE: I just supported iPhoneX and all device support for my old game...Apple recently approved this change...successfully added iPhoneX support to cocos2d 2.2