0

I use cocos2d 1.1, xCode 4.5 for my game's progect. I would like to recode my game for support the iPhone 5. But I faced with problem: cocos2d 1.1 can't detected sprite for retina 4 inch.

Default-568h@2x.png - work fine, but the game's sprites appears as *-hd.png. It seems cocos2d 1.1 can detected just *-hd.png, however I added the sprites *-568h@2x.png.

Sorry for my English.

The solving of this problem is in CCFileUtils.m file as written below sergio.

I did the little changes in method +(NSString*) getDoubleResolutionImage:(NSString*)path

+(NSString*) getDoubleResolutionImage:(NSString*)path
{
#if CC_IS_RETINA_DISPLAY_SUPPORTED

    if( CC_CONTENT_SCALE_FACTOR() == 2 )
    {
        NSString *pathWithoutExtension = [path stringByDeletingPathExtension];
        NSString *name = [pathWithoutExtension lastPathComponent];

        NSString *extension = [path pathExtension];

        if( [extension isEqualToString:@"ccz"] || [extension isEqualToString:@"gz"] )
        {
            extension = [NSString stringWithFormat:@"%@.%@", [pathWithoutExtension pathExtension], extension];
            pathWithoutExtension = [pathWithoutExtension stringByDeletingPathExtension];
        }

        CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;

        if ([UIScreen mainScreen].scale == 2.f && screenHeight == 568.0f)
        {
            if( [name rangeOfString:CC_RETINA4_DISPLAY_FILENAME_SUFFIX].location != NSNotFound ) {

                CCLOG(@"cocos2d: WARNING Filename(%@) already has the suffix %@. Using it.", name, CC_RETINA4_DISPLAY_FILENAME_SUFFIX);
                return path;
            }

            NSString *retinaName = [pathWithoutExtension stringByAppendingString:CC_RETINA4_DISPLAY_FILENAME_SUFFIX];
            retinaName = [retinaName stringByAppendingPathExtension:extension];

            if( [__localFileManager fileExistsAtPath:retinaName] )
            {   
                return retinaName;
            }
        }

        if( [name rangeOfString:CC_RETINA_DISPLAY_FILENAME_SUFFIX].location != NSNotFound ) {

            CCLOG(@"cocos2d: WARNING Filename(%@) already has the suffix %@. Using it.", name, CC_RETINA_DISPLAY_FILENAME_SUFFIX);
            return path;
        }

        NSString *retinaName = [pathWithoutExtension stringByAppendingString:CC_RETINA_DISPLAY_FILENAME_SUFFIX];
        retinaName = [retinaName stringByAppendingPathExtension:extension];
        if( [__localFileManager fileExistsAtPath:retinaName] )
        {   
            return retinaName;
        }

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

    }

#endif // CC_IS_RETINA_DISPLAY_SUPPORTED

    return path;
}

and also add in file ccConfig.h

#ifndef CC_RETINA4_DISPLAY_FILENAME_SUFFIX
#define CC_RETINA4_DISPLAY_FILENAME_SUFFIX @"-568h@2x"
#endif

If someone have a notice, please write

4

2 回答 2

1

You can change suffix in ccConfig.h file

#ifndef CC_RETINA_DISPLAY_FILENAME_SUFFIX
#define CC_RETINA_DISPLAY_FILENAME_SUFFIX @"-hd"
#endif
于 2012-10-03T12:19:53.863 回答
1

As far as I know, there is no general support in Cocos2D 2.x for iPhone 5 -568h@2x images.

The only iPhone 5 specific support that was added to cocos2D 2.1 concerns the addition of a Default-568h@2x.png image to the Xcode template. Read the ChangeLog for details.

On the other hand, it is also true that in UIKit too there is no support for "-568h@2x images", so I don't think that cocos2D is going to add one.

On a more conceptual level, I understand that the general approach to supporting iPhone 5 resolution is not at the bitmap level (i.e., providing differently scaled images), rather at the layout level (i.e., changing the disposition or sizes of non-image UI elements). (If you think about it, we already have to manage x1 and x2 images, both for iPhone and iPad: this means 4 different versions for each image; adding another dimension to this would be crazy.)

If your app really does need using scaled images, then I guess you are on your own both when using UIKit and when using cocos2D.

On the bright side, if you give a look at CCFileUtils.h you can easily change it so that it supports the -568h@2x. If you want a discussion of this, have a look at this blog post which describes an analogous change but for the iPad 3. It might help you in building your own solution.

于 2012-10-03T13:51:48.497 回答