Flying in a 3D world
Let's now build a scene where we can fly by skipping colorful cubes.
Setting up a scene
By running the app built so far, you might have noticed that, when you select the Play button, the app crashes. This is because GameViewController
expects to be set up by the Storyboard where the view is actually SCNView
; because the view is a plain UIView
, it crashes.
To fix this issue, we need to build a slim GameViewController
from scratch:
import UIKit import QuartzCore import SceneKit class GameViewController: UIViewController { private let scnView = SCNView() private var scene: SCNScene! override func viewDidLoad() { super.viewDidLoad() scnView.frame = view.bounds view.addSubview(scnView) createContents() } override func prefersStatusBarHidden() ...
Get Swift: Developing iOS Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.