Swift3 SKTEXTEREATLAS是否可以从“中”加载线束;我的";捆绑而不是“打包”;主持人;捆

Swift3 SKTEXTEREATLAS是否可以从“中”加载线束;我的";捆绑而不是“打包”;主持人;捆,swift3,texturepacker,sktexture,texture-atlas,sktextureatlas,Swift3,Texturepacker,Sktexture,Texture Atlas,Sktextureatlas,我正在使用SWIFT3/SpriteKit屏幕保护程序,我的屏幕保护程序正常工作,但我无法加载纹理,因为当我执行以下操作时: // load texture atlas let textureAtlas = SKTextureAtlas(named: "Flyers") SKTextureAtlas正在主捆绑包中寻找“传单”,当在screensaverengine.app中运行时,主捆绑包中不是纹理所在的捆绑包 在我以前基于obj-c的屏幕保护程序中,我必须执行以下操作才能从捆绑包中加载图像:

我正在使用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(名为:imageName,in:bundle,compatibleWith:nil)
从任何捆绑包中获取图像,然后使用这些图像的字典轻松实例化您的atlas:

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)