Created
November 11, 2014 19:24
-
-
Save remirobert/17cb99af917fe9402b9f to your computer and use it in GitHub Desktop.
Preload data for SpriteKit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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