我在 xCode 项目中添加了许多 map 集 (folder.atlas),通常使用它们按名称为我的 Sprite 创建 SKTextures
。但是,现在我发现我可能需要在 Sprite Kit 和基于 UIView 的类之间共享一些图像。
SKTexture* texture = [[SKTextureAtlas atlasNamed:@"Jetpack"] textureNamed:imageName];
//how to get UIImage?
有没有办法让我在运行时从图集中获取 UIImage?
最佳答案
也许现在回答这个问题已经太晚了,但这是我们在开发 Sprite 套件时非常常见的问题。苹果没有提供任何功能来直接解决这个问题。我所做的对我来说效果很好。
我需要访问来自 atlas dynamite 的任何图像。
NSString *str = imageName;
str = [str stringByReplacingOccurrencesOfString:@".png" withString:@""];
str = [[str componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"0123456789"]] componentsJoinedByString:@""];
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:str];
UIImage *atlasImage;
if (atlas.textureNames.count > 1)
{
SKTexture *texture = [atlas textureNamed:[atlas.textureNames objectAtIndex:0]];
atlasImage = [UIImage imageWithCGImage:texture.CGImage];
}
关于iphone - iOS7 我可以从添加到 xCode 项目的图集中访问图像(不是纹理)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20689261/