ios - How do I set the initial scene in a sprite kit project? -
i have 2 skscenes gamescene
, menuscene
, default scene appears when open app gamescene
want menuscene appear first
i tried change code in gameviewcontroller:
import uikit import spritekit extension sknode { class func unarchivefromfile(file : string) -> sknode? { if let path = nsbundle.mainbundle().pathforresource(file, oftype: "sks") { var scenedata = nsdata(contentsoffile: path, options: .datareadingmappedifsafe, error: nil)! var archiver = nskeyedunarchiver(forreadingwithdata: scenedata) archiver.setclass(self.classforkeyedunarchiver(), forclassname: "skscene") let scene = archiver.decodeobjectforkey(nskeyedarchiverootobjectkey) as! menuscene archiver.finishdecoding() return scene } else { return nil } } } class gameviewcontroller: uiviewcontroller { override func viewdidload() { super.viewdidload() if let scene = menuscene.unarchivefromfile("menuscene") as? menuscene { // configure view. let skview = self.view as! skview skview.showsfps = true skview.showsnodecount = true /* sprite kit applies additional optimizations improve rendering performance */ skview.ignoressiblingorder = true /* set scale mode scale fit window */ scene.scalemode = .aspectfill skview.presentscene(scene) } }
but shows grey screen not scene, there else need make?
is menuscene
sks
file? not, have swift
file scene.
if understand correctly, unarchiver takes sks
file , unarchives it, @ "unarchivefromfile" method, see if statement, , else returns nil.
you can this:
if let scene = new menuscene() {
instead of unarchive. otherwise make sks
version of menuscene
file.
Comments
Post a Comment