warning : not for the faint of heart.
I am using a single set of textures for all devices (the -hd variant). While implementing that i found that the contentScaleForKey
method in CCFileUtils
returns a bum value. I found no other way than doctoring that in cocos' distribution, as follows :
-(CGFloat) contentScaleForKey:(NSString*)k inDictionary:(NSDictionary *)dictionary
{
// XXX XXX Super Slow
// ylb fix for single set of textures
return 2.0f;
// ylb : super fast now :)
}
I set this up as follows in AppDelegate (version 3.2.1) :
@implementation AppDelegate
NSString *kCCFileUtilsSuffixDefault = @"default";
NSString *kCCFileUtilsSuffixiPad = @"ipad";
NSString *kCCFileUtilsSuffixiPadHD = @"ipadhd";
NSString *kCCFileUtilsSuffixiPhone = @"iphone";
NSString *kCCFileUtilsSuffixiPhoneHD = @"iphonehd";
NSString *kCCFileUtilsSuffixiPhone5 = @"iphone5";
NSString *kCCFileUtilsSuffixiPhone5HD = @"iphone5hd";
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// This is the only app delegate method you need to implement when inheriting from CCAppDelegate.
// This method is a good place to add one time setup code that only runs when your app is first launched.
// Setup Cocos2D with reasonable defaults for everything.
// There are a number of simple options you can change.
// If you want more flexibility, you can configure Cocos2D yourself instead of calling setupCocos2dWithOptions:.
// [[CCFileUtils sharedFileUtils] setEnableiPhoneResourcesOniPad:YES];
[GEFileUtil initializeWithProductDirectoryName:@"battles" andMaximumGames:4];
TRACE(@"Setting up cocos2d in fixed screen mode");
[GERuntimeConstants setDeviceType:CCScreenModeFixedSize];
NSDictionary *dic = [CCFileUtils sharedFileUtils].suffixesDict;
[dic setValue:@"-hd" forKey:kCCFileUtilsSuffixDefault];
[dic setValue:@"-hd" forKey:kCCFileUtilsSuffixiPhone];
[dic setValue:@"-hd" forKey:kCCFileUtilsSuffixiPad];
[dic setValue:@"-hd" forKey:kCCFileUtilsSuffixiPadHD];
[dic setValue:@"-hd" forKey:kCCFileUtilsSuffixiPhoneHD];
[dic setValue:@"-hd" forKey:kCCFileUtilsSuffixiPhone5];
[dic setValue:@"-hd" forKey:kCCFileUtilsSuffixiPhone5HD];
[self setupCocos2dWithOptions:@{
// Show the FPS and draw call label.
CCSetupShowDebugStats : @(YES),
// More examples of options you might want to fiddle with:
// (See CCAppDelegate.h for more information)
// Use a 16 bit color buffer:
// CCSetupPixelFormat: kEAGLColorFormatRGB565,
// Use a simplified coordinate system that is shared across devices.
CCSetupScreenMode : CCScreenModeFixed,
// Run in landscape mode.
CCSetupScreenOrientation : CCScreenOrientationLandscape,
// Run at a reduced framerate. Prefer that to 'dang' jitter
CCSetupAnimationInterval : @(1.0 / 30.0),
// Run the fixed timestep extra fast.
CCSetupFixedUpdateInterval : @(1.0 / 60.0),
// clipping with stensil
CCSetupDepthFormat : [NSNumber numberWithUnsignedInt:GL_DEPTH24_STENCIL8_OES],
// Make iPad's act like they run at a 2x content scale. (iPad retina 4x)
// CCSetupTabletScale2X: @(YES),
}];
Works on all devices now, with the caveat that i must be extra careful if i want to update cocos2d (NEVER mid-project in my bit factory).