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

Can SKTextureAtlas load bundle from "my" bundle instead of "host" bundle?

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

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

SKTextureAtlas 正在主包中寻找 "Flyers",当 运行 在 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];

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

我从未使用过 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)