swift - Why does my code return a bad access exception? -
i've got swift sprite kit project trying work on, whenever run game crashes on gameviewcontroller @ startup exc_bad_access code 1. here code:
class gameviewcontroller: uiviewcontroller { @iboutlet var imagebanner: uiimageview? @iboutlet var textbanner: uilabel? @iboutlet var playbutton: uibutton? @iboutlet var sharebutton: uibutton? @iboutlet var infobutton: uibutton? var skview = skview() var scene = skscene() override func viewdidload() { super.viewdidload() print("view did load") skview = skview(frame: self.view.frame) print("1") scene = gamescene(size: skview.bounds.size) print("2") skview.showsfps = false print("3") skview.showsnodecount = false skview.ignoressiblingorder = true scene.scalemode = .aspectfill print("done") }
i guess it's worth noting "done" logged in console.
you should not create new skview
. , why creating scene variable initialized skscene()
never use?
please use code xcode generates gameviewcontroller
.
class gameviewcontroller: uiviewcontroller { override func viewdidload() { super.viewdidload() if let scene = gamescene(filenamed:"gamescene") { // 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) } } // more stuff here }