swift3 - SKTextureAtlas 可以从 "my"包而不是 "host"包加载包吗?

标签 swift3 texturepacker sktexture texture-atlas sktextureatlas

我正在开发 SWIFT3/SpriteKit 屏幕保护程序,我的屏幕保护程序可以正常工作,但我无法加载我的纹理,因为当我执行以下操作时:

// load texture atlas
let textureAtlas = SKTextureAtlas(named: "Flyers")

SKTextureAtlas 在 screensaverengine.app 中运行时在主包中寻找“传单”,这不是纹理所在的包。

在我旧的基于 obj-c 的屏幕保护程序中,我必须执行以下操作才能从包中加载图像:

thisBundle = [NSBundle bundleForClass:[self class]];
fileName=[[NSString alloc ] initWithFormat:@"flyer%d", flyNum];
picturePath = [thisBundle pathForResource:fileName ofType:@"png"];
flyerImage= [[NSImage alloc ] initWithContentsOfFile:picturePath];

在我开始在运行时加载图像和创建纹理之前,我想利用 Stackoverflow 家族寻求帮助……有什么想法吗?

最佳答案

我从未使用过 SpriteKit。

但是查看文档,从 iOS 8 开始,您可以使用 UIImage(named: imageName, in: bundle, compatibleWith: nil) 从任何捆绑,然后使用这些图像的字典轻松实例化您的图集:

let bundle = Bundle(for: type(of: self))
var dictionary = [String:Any]()
["textureName": "imageName"].forEach { textureName, imageName in
    dictionary[textureName] = UIImage(named: imageName, in: bundle, compatibleWith: nil)
}
let atlas = SKTextureAtlas(dictionary: dictionary)

关于swift3 - SKTextureAtlas 可以从 "my"包而不是 "host"包加载包吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41174487/

相关文章:

swift - 强制UILabel占用3行

ios - Swift 3 : Find out, 如果日期已更改 - 怎么办?

ios - Cocos2d加载纹理内存问题

sprite-kit - 如何在 Sprite 节点上运行两个 SKTexture Action 作为组 Action

sprite-kit - 如何确定 SKTexture 使用@2x 还是@3x 图像?

ios - Swift 3 Eureka Forms 更改按钮行字体颜色

ios - 如何在 Swift 3 中正确使用 Amazon Cognito iOS SDK?

android - 我们是否需要在 cocos2dx 中使用 Sprite 作为 2 的幂

android - 无法使用带有 stripwhitespace 选项的 libGDX 纹理打包器打包分辨率为 800x800 的图像?

ios - 场景编辑器:如果没有@ 2x,则无法指定纹理名称