Learn how to add card game mechanics into your Sprite Kit games using Swift!
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2296-card-game-mechanics-in-sprite-kit-with-swift
Learn how to add card game mechanics into your Sprite Kit games using Swift!
I’m having trouble building the starter project. It has multiple errors. I’ve tried fixing some, but a few are too difficult to figure out.
here is an up to date version of the SKNode extension:
extension SKNode {
class func unarchiveFromFile(file : NSString) -> SKNode? {
let path = NSBundle.mainBundle().pathForResource(file as String, ofType: "sks")
let sceneData = NSData(contentsOfURL: NSURL(fileURLWithPath: path!))!
let archiver = NSKeyedUnarchiver(forReadingWithData: sceneData)
archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! GameScene
archiver.finishDecoding()
return scene
}
}
Hello, this file has a whole mess of errors. I am using swift 2.0. Can somebody help me correct these errors. They are to difficult for me to figure out. I have been trying but no luck.
Same here, I hope that they always keep their code tutorials up to date when Swift versions come out.
ya, I am trying to figure it out now. Mind posting it if you figure it out.
Hi, I have resolved 3 errors but still have 2 more, but here is the solution for the 3 errors maybe will work with you.
in AppDelegate.swift
change the current func didFinishLaunchingWithOptions with :
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. return true }
and in GameViewController.swift change the extension SKNode with :
`extension SKNode {
class func unarchiveFromFile(file : NSString) -> SKNode? {
let path = NSBundle.mainBundle().pathForResource(file as String, ofType: "sks")
let sceneData = NSData(contentsOfURL: NSURL(fileURLWithPath: path!))!
let archiver = NSKeyedUnarchiver(forReadingWithData: sceneData)
archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! GameScene
archiver.finishDecoding()
return scene
}
}`
and in the same swift file go to supportedInterfaceOrientations function at the bottom and change the return values only with :
return UIInterfaceOrientationMask.AllButUpsideDown
and in the second return change it to :
return UIInterfaceOrientationMask.All
thanks. I will try it now and for the other errors. maybe they can help you on a site called stackoverflow