iphone - iOS7 我可以从添加到 xCode 项目的图集中访问图像(不是纹理)吗?

标签 iphone ios7 uiimage sprite-kit texture-atlas

我在 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/

相关文章:

iphone - 在 iPhone 5 中启动画面消失后主屏幕看起来像变化?

iphone - 将多个 View Controller 推送到导航 Controller 堆栈时出现问题

objective-c - iOS 7 自动控制系统 : Discovering the primary ANCS Service UUID

ios - ScreenShot Image - 点击点的周围区域

ios - 如何在 iOS 中复制图像?

ios - 如何加载合适的 Default.png 到 UIimageView?

iphone - Xcode 5命令行:体系结构“arm64”的无效部署目标“3.0.0”

ios - 在 CCPhysicsNode 上启用调试绘制会导致崩溃

ios - 内部带有 Splitview 的弹出框

ios - Google Map SDK 使用标记时使用的内存量不合理