swift - Scene created in Sprite kit level editor is not working -


i'm trying while. have main scene game named playscene. have pause button there. when player tapping button want load scene, named pausescene. visualy creating scene use sprite kit level editor. have 2 files pausescene.swiftand pausescene.sks. .sks content ( background now) isn't unarchiving. don't know make mistake. transition via pause button, located in playscene

for touch: anyobject in touches {     let location = touch.locationinnode(self)         if self.nodeatpoint(location) == self.pause {             var scene = pausescene(size: self.size)             scene.paused = true             let skview = self.view skview!             skview.ignoressiblingorder = true             scene.scalemode = .aspectfill             scene.size = skview.bounds.size             skview.presentscene(scene)         }     }     

and have in pausescene.swift:

class pausescene: skscene { override func didmovetoview(view: skview) {     self.initpausescene() } func initpausescene() {  } 

}

i tried this , it's not working well. that tutorial closest problem. it's not crushing , isn't showing errors, when tap pause button it's transitioning scene without background, standard grey scene. this answer not working me. first suggestion show errors , when tried second , tap pause – game crushing. don't know, level editor made easier work know doubles me. thought problem in background image maybe. standard .png. why content isn't showing up? tried copy gameviewcontroller default code loading gamescene , ended crashing. it's not first time have that error while trying unarchive this. mean? got when tried replace var scene = pausescene(size: self.size) if let scene = pausescene.unarchivefromfile("pausescene") as? pausescene

it may transition grey scene due spelling errors or file not being in mainbundle. have tested , works. need make sure writing exact name of .sks file when loading or else grey screen.

example

if file called gamescreen.sks , class called gamescene if put class name when loading .sks file grey screen.

let doors = sktransition.doorwaywithduration(1.0) let archeryscene = gamescene(filenamed: "gamescreen") self.view?.presentscene(archeryscene, transition: doors) 

so if @ second line of code, see loading .sks file name gamescreen opposed class name gamescene. abort using file extension because compiler know default .sks file searching in mainbundle.

if keep getting grey screen, may error in spelling or ing gameviewcontroller, in sknode extension, sure change

extension sknode {     class func unarchivefromfile(file : nsstring) -> 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) gamescene         archiver.finishdecoding()         return scene     } else {         return nil     } } } 

to this..

 extension sknode {     class func unarchivefromfile(file : nsstring) -> 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) skscene         archiver.finishdecoding()         return scene     } else {         return nil     }    } } 

we edited line of code,

 let scene = archiver.decodeobjectforkey(nskeyedarchiverootobjectkey) gamescene 

to this

 let scene = archiver.decodeobjectforkey(nskeyedarchiverootobjectkey) skscene 

this allow load multiple .sks files without errors or crashes.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -