ios - Game restarts after segue to gameOverViewcontroller -
i have problem sprite kit game, restart after use model segue gameoverviewcontroller.
fps gets divide 2 after each time restart game.
need way delete game after use segue.
have tried self.dismissviewcontrolleranimated(true, completion: nil) don't know should put.
i have in storyboard 3 view controllers 1 start uses button modal segue second 1 have game scene played.
override func viewwilllayoutsubviews() { super.viewwilllayoutsubviews() print("start vc") // configure view. let skview = self.view as! skview skview.showsfps = true skview.showsnodecount = true skview.multipletouchenabled = true /* sprite kit applies additional optimizations improve rendering performance */ skview.ignoressiblingorder = true /* set scale mode scale fit window */ scene = gamescene(size: skview.bounds.size) scene.scalemode = .aspectfill scene.viewcontroller = self skview.presentscene(scene) }
at end when player dies use in game scene.swift
self.viewcontroller?.performseguewithidentifier("gameover", sender: self.viewcontroller!)
and in gameviewcontroller.swift
override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { if segue.identifier == "gameover" { let destviewcontroller: gameoverviewcontroller = segue.destinationviewcontroller as! gameoverviewcontroller destviewcontroller.score = scene.score destviewcontroller.screenshot = scene.image print("segue") scene.viewcontroller = nil } }
to go third view controller.
now have put multiple print command throwout code.
, saw game automatically restarts after segue completed. has body idee how solve problem or knows how maybe should use dismiss function.
thanks in regards
viewwilllayoutsubviews
of current view controller called when changing view controller.
so in case protect view scene won't created twice (thus, game restart) :
override func viewwilllayoutsubviews() { super.viewwilllayoutsubviews() print("start vc") // configure view. let skview = self.view as! skview if skview.scene == nil { // check makes sure won't create scene twice skview.showsfps = true skview.showsnodecount = true skview.multipletouchenabled = true /* sprite kit applies additional optimizations improve rendering performance */ skview.ignoressiblingorder = true /* set scale mode scale fit window */ scene = gamescene(size: skview.bounds.size) scene.scalemode = .aspectfill scene.viewcontroller = self skview.presentscene(scene) } }
Comments
Post a Comment