Get a list of all SpriteKit Scenes in App Bundle

浪子不回头ぞ 提交于 2020-01-16 19:24:48

问题


As a followup to this question, I need to iterate over each .sks file in a folder, namely, "Levels".

My project looks like this:

Here's what I've written:

let directory = NSFileManager.defaultManager().currentDirectoryPath
let paths = NSBundle.mainBundle().pathsForResourcesOfType("sks", inDirectory: directory)
let files = paths.map() { (path : AnyObject) -> String in
    return (path as String).lastPathComponent
}
println("Files\n\(files)")
let firstLevel = files[0]

if let scene = SKScene.unarchiveFromFile(firstLevel) {
    // Never reached because firstLevel is AParticleFile
}

With the output:

"[AParticleFile.sks, Level1.sks, Level2.sks]"

The problem is that AParticleFile.sks is a SpriteKit particle system, not an SKScene. It doesn't exist in the "Levels" directory, but I don't know how to get only the files in the "Levels" directory. What I've tried is directory.stringByAppendingPathComponent("Levels").

来源:https://stackoverflow.com/questions/25713326/get-a-list-of-all-spritekit-scenes-in-app-bundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!