Skip to content

Instantly share code, notes, and snippets.

@remirobert
Created November 11, 2014 19:24
Show Gist options
  • Save remirobert/17cb99af917fe9402b9f to your computer and use it in GitHub Desktop.
Save remirobert/17cb99af917fe9402b9f to your computer and use it in GitHub Desktop.
Preload data for SpriteKit
import UIKit
import SpriteKit
class PreloadData: NSObject {
var data = Dictionary<String, AnyObject>()
class var sharedInstance: PreloadData {
struct Static {
static let instance: PreloadData = PreloadData()
}
return Static.instance
}
class func addData(data: AnyObject, key: String) {
self.sharedInstance.data[key] = data
}
class func getData(key: String) -> AnyObject! {
return self.sharedInstance.data[key]
}
class func makeSKSPriteNode(key: String) -> SKSpriteNode! {
if let texture: AnyObject = self.sharedInstance.data[key] {
if texture.isKindOfClass(SKTexture.self) {
return SKSpriteNode(texture: (texture as SKTexture))
}
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment