在iPad视网膜@ 2x正确加载,但-hd加载半尺寸,即使图像相同

时间:2015-05-18 04:02:44

标签: ios ipad cocos2d-iphone retina-display

除了后缀之外,@ 2x图像与-hd图像完全相同。包括@ 2x和-hd允许程序在所有设备上正常运行,但显然我想摆脱一组来减少文件大小。

使用[sharedFileUtils setiPadSuffix:@"@2x"]时,iPad会使用@ 2x图像,一切都很棒。加载正确的内容规模和所有内容。

使用[sharedFileUtils setiPadSuffix:@"-hd"]时,iPad会使用-hd图像(使用[sharedFileUtils fullPathForFilename:@"image.png"]进行检查。但是,所有内容都会以50%的大小突然加载。

(我正在运行Cocos2d 3.4.3和Xcode 6.1.1)

为什么要这样做?

1 个答案:

答案 0 :(得分:0)

警告:不是为了胆小的人。

我正在为所有设备使用一组纹理(-hd变体)。实现时,我发现contentScaleForKey中的CCFileUtils方法返回了一个bum值。我发现除了在科科斯的发行中进行篡改之外别无其他方法,如下:

-(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 :)
}

我在AppDelegate(版本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),
    }];

现在可以在所有设备上使用警告,如果我想更新cocos2d(我的位工厂中的项目中间),我必须格外小心。