O'Reilly logo

Swift by Example by Giordano Scalzo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Flying in a 3D world

Let's now build a scene where we can fly, by skipping colorful cubes.

Setting up the scene

By running the app built so far, you might have noticed that on selecting the Play button, the app crashes. This is because GameViewController expects to be set up by the storyboard where the view is actually an SCNView, and 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() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required