我只是好奇人们使用什么方法在通用 iPhone/iPad 应用程序中动态使用更大或更小的图像。
我创建了一个大的测试图像,并尝试缩小(使用 cocos2d)0.46875。在 iPhone 4.0 模拟器中查看后,我发现结果非常糟糕......像素边缘粗糙等。此外,在 iPhone 用户不需要时加载巨大的图像文件是非常蹩脚的。
所以我想我可能要做的就是保存每个 Sprite 的两个版本......大(用于 iPad 端)和小(用于 iPhone/iPod Touch),然后检测用户的设备并吐出正确的像这样的 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];
你们是怎么做的?我宁愿避免在我的所有代码中使用这样的 if 语句。我还想避免使用 .xib 文件,因为它是基于 OpenGL 的应用程序。
谢谢!
最佳答案
我写了一些宏助手:
#define deviceFile(file, ext) \
([[UIDevice currentDevice].model rangeOfString:@"iPad"].location != NSNotFound ? \
[NSString stringWithFormat:@"%@-iPad.%@", file, ext] : \
[NSString stringWithFormat:@"%@.%@", file, ext])
用法:
// outputs either "test.png" or "test-iPad.png" depending on the user's device
CCSprite *test = [CCSprite spriteWithFile:deviceFile(@"test", @"png")];
关于iphone - 在 iPhone/iPad 通用应用程序中管理图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2796906/