xcode - Calling GameScene.swift files through ViewController.swift files [Swift 3.0 Spritekit] -


i have been trying use uibuttons 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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -