问题描述
我需要为我的GameViewController添加一个游戏循环(来自Swift游戏模板,用于iOS开发),以便创建一个应用程序并找到这个参考页面,解释如何执行此操作:
I need to add a game loop to my GameViewController (From the Swift "Game" template for iOS development) in order to create an application and found this reference page explaining how to do this:
然而,当我尝试将SCNView的委托设置为ViewController它会抛出警告和错误(在viewDidLoad()内部):
However when I try to set the delegate of the SCNView to be the ViewController it throws up warnings and errors (inside viewDidLoad()):
gameView.delegate = self
其中gameView连接到我的故事板中的SCNView:
Where gameView is connected to an SCNView in my storyboard:
@IBOutlet weak var gameView: SCNView!
如果有人可以链接使用Swift和Scene Kit设置游戏逻辑的代码示例,那将是很棒的或者从头开始向我解释。谢谢!
It would be brilliant if someone could link a code example of setting up game logic using Swift and Scene Kit or explain it to me from the ground up. Thank you!
推荐答案
当你指定:
gameView.delegate = self
这需要 self
是一个声明符合 SCNSceneRendererDelegate
协议的类。要使您的视图控制器类声明协议一致性,请使用描述的语法:
This requires that self
be a class that declares conformance to the SCNSceneRendererDelegate
protocol. To make your view controller class declare protocol conformance, use the syntax described in the Swift book:
class ViewController: UIViewController, SCNSceneRendererDelegate {
// ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ ^
// ^- superclass ^- protocol |
// more protocols if you conform to them --/
// ... rest of class definition ...
}
这篇关于向Scene Kit(Swift)添加自定义游戏逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!