[英]Cocos2d-iPhone and iPhone X resolution
Can you believe we are still using Cocos2d-iPhone?你能相信我们还在使用 Cocos2d-iPhone 吗?
Does anyone have a fix for making it work with the newest iPad's and iPhone X's?有没有人有办法让它在最新的 iPad 和 iPhone X 上工作?
Our mode is landscape.我们的模式是横向。
In CCConfiguration.m file updated below function.在 CCConfiguration.m 文件中更新了以下功能。 In this we are handling contentScaleFactor 3.
在这里,我们正在处理 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使用 iPhone5HD 中的按钮和其他图像并手动加载 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或者只是缩放 bg 图像
#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注意:我只支持 iPhoneX 和我的旧游戏的所有设备支持...Apple 最近批准了此更改...成功地将 iPhoneX 支持添加到 cocos2d 2.2
Guru's solution is incomplete. Guru 的解决方案是不完整的。 His solution loads iPhone X images in a scale of 2 (1624x750) instead of 3 (2436×1125).
他的解决方案以 2(1624x750)而不是 3(2436×1125)的比例加载 iPhone X 图像。 So you need to set the scale of the device to 3. In setContentScaleFactor from CCDirectiorIOS.m you have to add:
因此您需要将设备的比例设置为 3。在 CCDirectiorIOS.m 的 setContentScaleFactor 中,您必须添加:
if([UIScreen mainScreen].scale == 3.0f)
__ccContentScaleFactor = 3;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.