为了解决这个问题,我不得不想出一种方法来缓存纹理,以使其不会重复:
private var textureCache = [String: SKTexture]()extension SKTextureAtlas{ func texturesWithNames(_ names:[String]) -> [SKTexture] { var textures = [SKTexture]() names.forEach({textures.append(textureNamed($0))}) return textures } func cachedTextureWithName(_ name:String) -> SKTexture { if textureCache[name] == nil { textureCache[name] = textureNamed(name) } return textureCache[name]! } func cachedTexturesWithNames(_ names:[String]) -> [SKTexture] { var textures = [SKTexture]() names.forEach({textures.append(cachedTextureWithName($0))}) return textures } func clearCache() { textureCache = [String: SKTexture]() }}extension SKTexture{ var name : String { return self.description.slice(start: "'",to: "'")! }}


