I have been trying to learn how to use delegates recently and actually seem to understand it for the most part. However I have one problem.
I have 1 GameViewController, 1 StartScene and 1 MenuScene
In my GameViewController I have 2 methods that I would like to get called from MenuScene. So far I have been using NSNotification, which works fine but I am trying to use delegates.
So I have set up a protocol in MenuScene
protocol MenuSceneDelegate {
func gameOver()
func showGameCenter()
}
I than referenced it like so
var menuSceneDelegate: MenuSceneDelegate?
In GameViewController I added the MenuSceneDelegate at the top. All is very standard so far. However the main problem I have is that when I set the delegate in GameViewController like so
let skView = view as! SKView!
var scene = StartScene(size: skView.bounds.size)
skView.ignoresSiblingOrder = true
scene.scaleMode = .ResizeFill
skView.presentScene(scene)
scene.menuSceneDelegate = self //Sets delegate to StartScene not MenuScene
it only applies to the StartScene. How can I set the GameViewController delegate from StartScene to MenuScene. Everything works fine if I would first present the MenuScene. However I present StartScene first and therefore I am trying to understand how I set the delegate to MenuScene.
I tried something like this below but it doesnt work and just doesnt seem right
var menuScene = MenuScene(size: skView.bounds.size)
menuScene.menuSceneDelegate = self
I would appreciate any help or support. Thank you very much