Reputation: 131
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:
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
Where gameView is connected to an SCNView in my storyboard:
@IBOutlet weak var gameView: SCNView!
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!
Upvotes: 1
Views: 1187
Reputation: 126167
When you assign:
gameView.delegate = self
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 ...
}
Upvotes: 4