简体   繁体   English

如何从SKScene到UIViewController?

[英]How to get from SKScene to UIViewController?

I am new to programming and I am trying to build a simple game using Swift and SpriteKit. 我是编程新手,我正在尝试使用Swift和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? 如何从故事板中的SKScene(游戏)到UIViewController?

My game looks like this. 我的游戏看起来像这样。 In the Storyboard i have 3 views (Main menu, About and Game Over) and 1 SKScene (Game). 在故事板中我有3个视图(主菜单,关于和游戏结束)和1个SKScene(游戏)。 When the player clicks on the play button in the main menu he gets to the game SKScene. 当玩家点击主菜单中的播放按钮时,他会进入游戏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). 当玩家失败时,我想要一个新的UIViewController,我可以链接2个按钮(返回主菜单并重新启动)。

I don't know how to do this. 我不知道该怎么做。 I will also accept Objective-C if you don't know in Swift. 如果您不熟悉Swift,我也会接受Objective-C。

For others encountering this problem down the road: 对于其他人在路上遇到这个问题:

self.view?.window?.rootViewController

will return a UIViewController object when called in a SKScene . SKScene调用时将返回UIViewController对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM