2

我工作的一個SWIFT3/SpriteKit屏幕保護程序和我有屏幕,除了我的工作不能讓我的紋理加載,因爲當我做到以下幾點:SKTextureAtlas是否可以從「my」包而非「host」包中加載包?

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

的SKTextureAtlas正在尋找「飛人」在當在screensaverengine.app內部運行時,主捆綁包不是紋理所在的捆綁包。

在我以前的對象 - 基於屏幕保護程序,我不得不做以下從包中加載圖片:

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

之前,我去加載圖像,並在運行時創建的紋理的路線,我想要點擊Stackoverflow家庭的一些幫助...想法?

回答

0

我從來沒有使用過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)