您可以相信我们仍在使用Cocos2d-iPhone吗?
是否有人可以使其与最新的iPad和iPhone X配合使用?
我们的模式是风景。
答案 0 :(得分:2)
在CCConfiguration.m文件中更新了以下功能。在此,我们正在处理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;
}
使用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
}
或者只是缩放背景图片
#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;
}
应用委托代码:
-(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;
}
注意::我刚刚支持iPhoneX和旧游戏的所有设备支持...苹果最近批准了此更改...已将cocos2d 2.2新增了对iPhoneX的支持
答案 1 :(得分:0)
大师的解决方案不完整。他的解决方案以2(1624x750)而不是3(2436×1125)的比例加载iPhone X图像。因此,您需要将设备的比例设置为3。在CCDirectiorIOS.m的setContentScaleFactor中,您必须添加:
if([UIScreen mainScreen].scale == 3.0f)
__ccContentScaleFactor = 3;