问题
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:
https://developer.apple.com/library/prerelease/ios/documentation/SceneKit/Reference/SCNSceneRendererDelegate_Protocol/
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!
回答1:
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 ...
}
来源:https://stackoverflow.com/questions/27847828/adding-custom-game-logic-to-scene-kit-swift