Currently you are supposed to do it by name in the method added to the SpriteKit game templates. They cover this topic in the SpriteKit Best Practices video in WWDC 2014. It's easy to miss because the video has a lot in it.
Here is the method.
+ (instancetype)unarchiveFromFile:(NSString *)file {
/* Retrieve scene file path from the application bundle */
NSString *nodePath = [[NSBundle mainBundle] pathForResource:file ofType:@"sks"];
/* Unarchive the file to an SKScene object */
NSData *data = [NSData dataWithContentsOfFile:nodePath
options:NSDataReadingMappedIfSafe
error:nil];
NSKeyedUnarchiver *arch = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
[arch setClass:self forClassName:@"SKScene"];
SKScene *scene = [arch decodeObjectForKey:NSKeyedArchiveRootObjectKey];
[arch finishDecoding];
return scene;
}
It's a category on SKScene
that includes a method to use NSKeyedUnarchiver
to substitute the Class when loaded from the .sks file in the mainBundle. In iOS they add it to the GameViewController.m
file and in OS X they add it to the AppDelegate.m
file.
In here or in your individual SKNode subclasses, you can implement this. This is what he did below in his post. This was provided by Apple and covered in the WWDC video. I guess next year it will get handled better. In the meantime file a bug requesting SKNodes get something like IBDesignable for Scene Editor. :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…