iphone - Is it possible to connect a SceneView to a GameScene without storyboard? [iOS SWIFT] -
i have 2 scenes. first (presentscene) connected presentsceneview second scene (gamescene) not connected gamesceneview.
presentsceneview created on storyboard not gamesceneview , don't want create it.
is possible connect gamescene gamesceneview without create on storyboard?
here gamesceneview code(doesn't work)
import uikit import spritekit import avfoundation var backgroundmusicplayer:avaudioplayer = avaudioplayer() class gameviewcontroller: uiviewcontroller { override func viewdidload() { super.viewdidload() } override func viewwilllayoutsubviews() { var skview:skview = self.view skview skview.showsfps = true skview.showsnodecount = true skview.showsphysics = true var scene:skscene = gamescene.scenewithsize(skview.bounds.size) scene.scalemode = skscenescalemode.aspectfill skview.presentscene(scene) var bgmusicurl:nsurl = nsbundle.mainbundle().urlforresource("fond", withextension: "mp3")! backgroundmusicplayer = avaudioplayer(contentsofurl: bgmusicurl, error:nil) backgroundmusicplayer.numberofloops = -1 backgroundmusicplayer.preparetoplay() backgroundmusicplayer.play() } override func shouldautorotate() -> bool { return true } override func supportedinterfaceorientations() -> int { if uidevice.currentdevice().userinterfaceidiom == .phone { return int(uiinterfaceorientationmask.allbutupsidedown.toraw()) } else { return int(uiinterfaceorientationmask.all.toraw()) } } override func didreceivememorywarning() { super.didreceivememorywarning() // release cached data, images, etc aren't in use. } override func prefersstatusbarhidden() -> bool { return true }
}
thank you
let gamescene = gamescene(size: skview.bounds.size) gamescene.scalemode = .aspectfill skview.presentscene(gamescene) instead of var scene:skscene = gamescene.scenewithsize(skview.bounds.size) scene.scalemode = skscenescalemode.aspectfill skview.presentscene(scene)
Comments
Post a Comment