google-code-export / los-cocos

Automatically exported from code.google.com/p/los-cocos
Other
1 stars 0 forks source link

Retina images (-hd, -ipadhd) in main bundle are not recognized if non-retina counterpart is not present #179

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
this affects all cocos2d versions (haven't tested 2.0)

1. put an image in main bundle and name it "image-ipadhd.png"
2. try loading the image with [CCSprite spriteWithFile:@"image-ipadhd.png"]
output will show warning:
cocos2d: CCFileUtils: Warning file not found: image.png

I always load files with the suffix included, this way I can use retina iPhone 
assets on non-retina iPad.
But there is a bug in CCFileUtils where after the suffix is stripped, the class 
only checks the existence of the non-retina file, which doesn't exist in this 
case.

I've added an additional check and now it seems to be working:
(Line 121)

    NSString *newName = [pathWithoutExtension stringByAppendingString:suffix];
    newName = [newName stringByAppendingPathExtension:extension];

    /// HACK!!!

    CCLOG(@"newName: %@", newName);

    NSString *newPath = nil;

    // only if it is not an absolute path
    if( ! [newName isAbsolutePath] ) {
        // pathForResource also searches in .lproj directories. issue #1230
        NSString *file = [newName lastPathComponent];
        NSString *imageDirectory = [newName stringByDeletingLastPathComponent];

        newPath = [[NSBundle mainBundle] pathForResource:file
                                                   ofType:nil
                                              inDirectory:imageDirectory];

    }

    if (newPath != nil)
        newName = newPath;

    CCLOG(@"newName: %@", newName);
    /// END HACK

    if( [__localFileManager fileExistsAtPath:newName] )
        return newName;

    CCLOG(@"cocos2d: CCFileUtils: Warning file not found: %@", [newName lastPathComponent] );

Original issue reported on code.google.com by phil...@gmail.com on 6 Jun 2012 at 9:51

GoogleCodeExporter commented 9 years ago
Use the cocos2d-iphone issue tracker for cocos2d-iphone bugs. Thanks.
http://code.google.com/p/cocos2d-iphone/issues/list

Original comment by ricardoq...@gmail.com on 6 Jun 2012 at 5:10

GoogleCodeExporter commented 9 years ago
wrong issue tracker, closing

Original comment by ccanepacc@gmail.com on 6 Jun 2012 at 9:11