无论您采用哪种方式,都会遇到缩放问题(偏移量和字体),但它对我有用。我没有在视网膜 ipad 上启用视网膜 :) 并使用我的 -hd 纹理。另外对于背景纹理,我系统地使用 1136x768 图片......它们适用于所有设备(在 3.5 iPhone 和 iPad 上裁剪)。唯一需要注意的是,如果您想要一个具有“边框”功能的背景纹理,则每种设备类型都需要一个,并且在运行时有一些“if”语句来选择合适的纹理。
这是我的 AppController 启动
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[director_ enableRetinaDisplay:NO];
MPLOG(@"iPad device detected : forcing non-retina !");
[constants setAsIpad];
isIpadDevice = YES;
}
else {
isIpadDevice = NO;
if (![director_ enableRetinaDisplay:YES]) {
MPLOG(@"Retina Display Not supported");
}
else {
CGSize portrait = [CCDirector sharedDirector].winSize;
CGSize landscape = CGSizeMake(portrait.height, portrait.width);
if (landscape.width >= 568.) {
[constants setAsIphoneIpodTall];
} else {
[constants setAsIphoneIpodSmall];
}
}
}
MPLOG(@"Retina display : %@", NSStringFromBool(kIsRetina));
MPLOG(@"Scale factor : %.0f", director_.contentScaleFactor);
MPLOG(@"Screen size : {%.0f, %.0f}", kScreenWidth, kScreenHeight);
MPLOG(@"Tile size : {%.0f, %.0f}", kTileWidth, kTileHeight);
MPLOG(@"Battle mid point : %@", NSStringFromCGPoint(kBattleMidPoint));
MPLOG(@"Menu width : %4i", kMapRightMenuWidth);
// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
if (deviceTypeIpodTall == kDeviceType) {
[GESprite setDefaultPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
MPLOG(@"Pixel resolution : RGBA8888") ;
}
else {
if (isIpadDevice) {
[GESprite setDefaultPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
MPLOG(@"Pixel resolution : RGBA8888") ;
}
else {
[GESprite setDefaultPixelFormat:kCCTexture2DPixelFormat_RGBA4444];
MPLOG(@"Pixel resolution : RGBA4444") ;
}
}
[GESprite defaultPixelFormat];
// If the 1st suffix is not found and if fallback is enabled then fallback suffixes are going to searched. If none is found, it will try with the name without suffix.
// On iPad HD : "-ipadhd", "-ipad", "-hd"
// On iPad : "-ipad", "-hd"
// On iPhone HD: "-hd"
CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
[sharedFileUtils setEnableFallbackSuffixes:NO]; // Default: NO. No fallback suffixes are going to be used
[sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"]; // Default on iPhone RetinaDisplay is "-hd"
[sharedFileUtils setiPadSuffix:@"-hd"]; // Default on iPad is "ipad"
[sharedFileUtils setiPadRetinaDisplaySuffix:@"-hd"]; // Default on iPad RetinaDisplay is "-ipadhd"
// Assume that PVR images have premultiplied alpha
[CCTexture2D PVRImagesHavePremultipliedAlpha:NO];
在“常数”中(哈哈哈)
+(void)setAsIpad {
kDeviceType = deviceTypeIpadNormal;
kIsIpad = YES;
kIsIphoneIpod = NO;
kIsIphoneIpodTall = NO;
kMapRightMenuWidth = 0;
kMapBottomMenuHeight = 0;
kTileHeight = 80.;
kTileWidth = 80.;
kScreenWidth = 1024;
kScreenHeight = 768;
kIsRetina = NO;
kScreenSize = CGSizeMake(kScreenWidth, kScreenHeight);
kScreenMidPoint = ccp(kScreenWidth / 2, kScreenHeight / 2);
kMidScreen = kScreenMidPoint;
kBattleMidPoint = ccp(kScreenWidth / 2 - kMapRightMenuWidth / 2, kScreenMidPoint.y);
}