3

I am new to programming and I am trying to build a simple game using Swift and SpriteKit. It looks good now but I have a little problem to solve. How do I get from a SKScene (Game) to a UIViewController in the Storyboard?

My game looks like this. In the Storyboard i have 3 views (Main menu, About and Game Over) and 1 SKScene (Game). When the player clicks on the play button in the main menu he gets to the game SKScene. When the player fails I want to get to a new UIViewController where I can link 2 buttons (back to main menu and restart).

I don't know how to do this. I will also accept Objective-C if you don't know in Swift.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
PatrickDotStar
  • 1,654
  • 1
  • 19
  • 20
  • You need to devise a way for the SKScene to communicate with the UIViewController. Have a look at this answer: http://stackoverflow.com/a/22555881/2043580 – ZeMoon Aug 14 '14 at 12:28
  • possible duplicate of [How do I go from SKScene to UIViewController by code?](http://stackoverflow.com/questions/22549255/how-do-i-go-from-skscene-to-uiviewcontroller-by-code) – ZeMoon Aug 14 '14 at 12:30

1 Answers1

1

For others encountering this problem down the road:

self.view?.window?.rootViewController

will return a UIViewController object when called in a SKScene.

Whirlwind
  • 14,286
  • 11
  • 68
  • 157