ios - Instantiate a *game scene* view Swift -
so, trying instantiate view controller. issue is, view trying to instantiate gamescene view controller (sprite kit). also, view instituting from gamescene view. if instantiating normal uiviewcontroller, this:
let vc : anyobject! = self.storyboard!.instantiateviewcontrollerwithidentifier("main") self.showviewcontroller(vc as! uiviewcontroller, sender: vc) //the view instantiating's class name "gamescene"
when try run this, 2 errors:
gamescene not have member named "storyboard" 'gamescene' not have member named 'showviewcontroller'
can please explain why not work, , please post working solution?
thanks in advance!
this because game scene not have property called storyboard
or showviewcontroller
. these part of uiviewcontroller
class.
. access them inside gamescene
can create property inside gamescene pointing current uiviewcontroller
.
class gamescene: skscene { var gameviewcontroller : uiviewcontroller! }
you can assign property inside gameviewcontroller
class.
override func viewdidload() { super.viewdidload() if let scene = gamescene.unarchivefromfile("gamescene") as? gamescene { // configure view code scene.gameviewcontroller = self // added line skview.presentscene(scene) } }
then can use inside gamescene
this.
let vc : anyobject! = self.gameviewcontroller.storyboard!.instantiateviewcontrollerwithidentifier("main") self.gameviewcontroller.showviewcontroller(vc as! uiviewcontroller, sender: vc)
Comments
Post a Comment