ios - SKScene getting slower after every restart -
this code. assume because deinit never called, , every time user starts playing (gamescene), memory jumps 20 mb 40 mb 60, etc. , fps goes down after every time user dies , restarts game.
does know why?
gameviewcontroller.swift import uikit import spritekit extension sknode { class func unarchivefromfile(file : nsstring) -> sknode? { if let path = nsbundle.mainbundle().pathforresource(file string, 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! gamescene archiver.finishdecoding() return scene } else { return nil } } } class gameviewcontroller: uiviewcontroller{ @iboutlet var skscenereal: skview! override func viewdidload() { super.viewdidload() } override func viewwillappear(animated: bool) { if((self.skscenereal) != nil) { if let scene = gamescene.unarchivefromfile("gamescene") as? gamescene { // configure view. var skview = self.view as! skview skscenereal.showsfps = false skscenereal.showsnodecount = false /* sprite kit applies additional optimizations improve rendering performance */ skscenereal.ignoressiblingorder = true /* set scale mode scale fit window */ scene.scalemode = .aspectfill scene.viewcontroller = self skscenereal.presentscene(scene) } } } deinit { println("deinit worked") } override func viewwilldisappear(animated: bool) { self.skscenereal.removefromsuperview() self.skscenereal = nil; } override func shouldautorotate() -> bool { return true } override func supportedinterfaceorientations() -> int { if uidevice.currentdevice().userinterfaceidiom == .phone { return int(uiinterfaceorientationmask.allbutupsidedown.rawvalue) } else { return int(uiinterfaceorientationmask.all.rawvalue) } } override func didreceivememorywarning() { super.didreceivememorywarning() // release cached data, images, etc aren't in use. } override func prefersstatusbarhidden() -> bool { return true } }
gamescene.swift ... var gameending = false; func gameover(){ if(!gameending) { gameending = true; // deallocate/reset view/scene. // ???? dont know ???? // present move segue.(created in storyboard) source: gamevc, destination: gameovervc self.viewcontroller?.performseguewithidentifier("move", sender: self) } }
and there's modal segue gameviewcontroller button in gameoverviewcontroller (created in storyboard).
i got same problem. fixed nulling nodes on scene , instead of showing uiviewcontroller showing skscene instead. seemed solve problem , deallocating gamescene correctly.
this game on method:
- (void) gameover { [self removeallactions]; [self removeallchildren]; sktransition *reveal = [sktransition fliphorizontalwithduration:0.5]; skscene *newscene; newscene = [[gameoverscene alloc] initwithsize:self.size andnewhighscore:score]; [self.view presentscene:newscene transition: reveal]; }
Comments
Post a Comment