xcode - Calling GameScene.swift files through ViewController.swift files [Swift 3.0 Spritekit] -
i have been trying use uibutton
s game interface, still trying figure out how call methods inside gamescene
file through view controller file. there anyway can give view controller reference instance of gamescene being displayed on gamescene.sks file?
so far have tried in view controller:
// inside view controller class gameviewcontroller: uiviewcontroller { static var gamescene: gamescene = gamescene() func setgamescene(scene: gamescene) { gameviewcontroller.gamescene = scene } ...
this did in gamescene file.
//inside gamescene.swift class gamescene: skscene { override func didmove(to view: skview) { let vc = gameviewcontroller() vc.setgamescene(scene: self) } ...
you want create computed property view's scene
class gameviewcontroller: uiviewcontroller { var gamescene : gamescene? { return (view as? skview).scene as? gamescene} ... }
now needs optional, because there may times scene not gamescene
, , cause app crash.
Comments
Post a Comment