Image management in the universal iphone / ipad app
I'm just wondering what techniques people are using to dynamically use larger or smaller images in their universal iPhone / iPad apps.
I created a large test image and I tried to scale down (using cocos2d) by 0.46875. After watching this in the iPhone 4.0 simulator, I found the results were pretty crappy ... rough pixel edges, etc. Also, downloading huge image files for iPhone users when they don't need them is pretty lame.
So, I think what I probably have to do is save two versions of each sprite ... large (for iPad) and small (for iPhone / iPod Touch), then detect the user device and spit out the proper sprite:
NSString *deviceType = [UIDevice currentDevice].model;
CCSprite *test;
if([deviceType isEqualToString:@"iPad"]) {
test = [CCSprite spriteWithFile:@"testBigHuge.png"];
} else {
test = [CCSprite spriteWithFile:@"testRegularMcTiny.png"];
}
[self addChild: test];
How do you guys do it? I would rather avoid using all my code with statements like this. I also want to avoid using .xib files as this is an OpenGL based application.
Thanks!
a source to share
I wrote a little hint for macros:
#define deviceFile(file, ext) \
([[UIDevice currentDevice].model rangeOfString:@"iPad"].location != NSNotFound ? \
[NSString stringWithFormat:@"%@-iPad.%@", file, ext] : \
[NSString stringWithFormat:@"%@.%@", file, ext])
Using:
// outputs either "test.png" or "test-iPad.png" depending on the user device
CCSprite *test = [CCSprite spriteWithFile:deviceFile(@"test", @"png")];
a source to share
Specify each image in sequence with "Large" or "Small", but keep the other names the same for equivalent images.
There is a global value somewhere with the @ "Large" or @ "Small" value that you set at startup.
There is a method somewhere that will take a generic name string and insert a global size specifier.
@interface CCSprite (MyProject)
+(id) spriteWithSizedFile:(NSString *)inName;
@end
@implementation CCSprite(MyProject)
+(id) spriteWithSizedFile:(NSString *)inName {
return [CCSprite spriteWithFile:[gSizeSpecifier stringByAppendingString:inName]];
}
@end
Possibly a better spot than CCSprite. This is just an example.
a source to share