iphone - 在 iPhone/iPad 通用应用程序中管理图像

标签 iphone cocos2d-iphone ipad

我只是好奇人们使用什么方法在通用 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/

相关文章:

ios - 如何使用 livecode external rrhardcoy 在 ios7 ipad 中显示 airprint 弹出窗口?

iphone - 在 iPhone 中将 NSTimeInterval 转换为 NSString?

iphone - iPhone 应用程序中的音频反馈问题

cocos2d-iphone - Cocos2d + Box2d或花栗鼠

ios - 使用 glDrawArrays,iOS 损坏 OpenGL 纹理

javascript - iPad 上的曲线颜色是深灰色,而不是红色。如何解决这个问题?

iphone - 我应该在哪里初始化我的数据?

iphone - 检测通知中心设置

ios - CCMoveTo 不工作,节点/场景问题?

iphone - 如何从 tabbarcontroller 访问特定的 viewcontroller?