我正在使用Sprite Kit开发游戏。我想让它自动使用iPhone,iPad和大型iPhone版本所需的纹理。
让我们想象一下:
player01-568h.png - player-10-568h.png
player01@2x.png - player-10@2x.png
player01-ipad.png - player-10-ipad.png
player01-ipadhd.png - player-10-ipadhd.png
如何存储这些?
我是否需要单独的地图册?
每次我需要加载地图集和所需的负载时,是否检查设备,还是有自动方式?
答案 0 :(得分:3)
我找到了一个有用的方法,它为当前设备返回一个合适的纹理图集。
指定
#define IS_WIDESCREEN ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
在场景顶部并添加此方法:
- (SKTextureAtlas *)textureAtlasNamed:(NSString *)fileName {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if (IS_WIDESCREEN) {
// iPhone Retina 4-inch
fileName = [NSString stringWithFormat:@"%@-568", fileName];
} else {
// iPhone Retina 3.5-inch
fileName = fileName;
}
} else {
fileName = [NSString stringWithFormat:@"%@-ipad", fileName];
}
SKTextureAtlas *textureAtlas = [SKTextureAtlas atlasNamed:fileName];
return textureAtlas;
}
现在你需要做的就是正确命名你的纹理地图。
iPhone 3.5英寸:MyAtlas.atlas
iPhone 4英寸:MyAtlas-568.atlas
iPad:MyAtlas-ipad.atlas
抱歉,不记得我从哪里得到它。