0

The @2x images are completely identical to the -hd images, other than the suffix. Including both @2x and -hd allows the program to run on all devices properly, but obviously I'd like to get rid of one set to decrease the filesize.

When using [sharedFileUtils setiPadSuffix:@"@2x"], iPad uses the @2x images and everything is great. Loads at correct content scale and everything.

When using [sharedFileUtils setiPadSuffix:@"-hd"], the iPad does use the -hd images (checked with [sharedFileUtils fullPathForFilename:@"image.png"]. However, everything is suddenly loading at 50% size.

(I'm running Cocos2d 3.4.3 and Xcode 6.1.1)

Why is it doing this?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • What's `sharedFileUtils`? – rmaddy May 18 '15 at 04:05
  • Sorry, it's from CCFileUtils. It lets me overwrite the default suffix for loading images (ie ipad would usually look for -ipad before falling back on -hd). I'm not sure why adding the @2x suffix would allow images to load properly, honestly. – grasshopper May 18 '15 at 05:58
  • I am using a single set of textures for all devices. 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. 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). – YvesLeBorg May 18 '15 at 15:04
  • related question http://stackoverflow.com/questions/29853468/cocos2d-swift-v3-x-in-ipad-iphone-sd-images-are-used-ipad-suffix-ignored/29919806#29919806 – Guru May 22 '15 at 16:13
  • Shouldn't you be using ipadhd? – PWiggin Jun 05 '15 at 05:10
  • @YvesLeBorg if you add this as an answer I'll accept it! seems to be the best solution for now! – grasshopper Jun 30 '15 at 00:08

1 Answers1

0

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).

YvesLeBorg
  • 9,070
  • 8
  • 35
  • 48