Your hardware is ready, and now it’s time to build some software to test it out! In this step we will get up and running with the default iOS Game template, based on SceneKit. Get started by launching Xcode on your Mac.
Choose to “Create a new Xcode Project”.
In the template chooser, in the iOS Application section, choose “Game”.
Give your project a name and a unique identifier based on your name or your organization’s name. If you have a web domain, using reverse-domain notation is the convention. Use Swift and SceneKit. For this tutorial, we will focus on iPhone, so choose that option. Feel free to generate tests for your project, but we won’t be discussing them here.
In the next window, choose a location to save your project. You can check the box to initialize a Git repository if you want.
Once your project is loaded, you will see that Xcode has created several files for you. Let’s go over them.
AppDelegate.swift: This class is responsible for managing the lifetime of your application. We won’t be touching it in this tutorial, but you would put code here to respond to the events that are well documented in the file.
art.scnassets: This is a folder containing the test 3D model we will use to render our light field.
GameViewController.swift: This is where we will put the majority of our code. A view controller is responsible for controlling what is displayed on the screen.
Main.storyboard: This file defines the layout of our user interface. By default it is just a single view where our content is rendered, and we will leave it as is.
Assets.xcassets: This folder contains icon images for your app.
LaunchScreen.storyboard: This file defines the look of your launch screen.
Info.plist: This file defines several properties of your application. We won’t need to adjust these.
Take a closer look at
GameViewController.swift. In the
viewDidLoad() function, a new scene is loaded from file:
// create a new scene let scene = SCNScene(named: "art.scnassets/ship.scn")!
A camera and some lights are created, and the ship model’s properties are adjusted. Finally, the scene is assigned to the current view so it will be rendered.
// retrieve the SCNView let scnView = self.view as! SCNView // set the scene to the view scnView.scene = scene
Make sure the scheme selector in the upper left-hand corner is set to a valid simulator and click the Run button.
You should see an iOS simulator launch and render a spinning space ship.
As of this writing, the Xcode simulator only supports OpenGL ES 3D graphics. For this tutorial, we will be using the iOS Metal API for dramatically better performance. This means that in order to test your app, you will need to attach a real device.
Plug your iPhone in to your Mac and select it in the scheme selector.
It may say that it is loading symbols; you will have to wait for this process to complete before you continue.
Click the Run button. At this point, if you have never deployed an app to this device before, it will ask you to fix code signing issues. Unless you know better, choose to sign the app using your personal team—this is a developer account that you get for free to develop and deploy apps on your personal devices. It is tied to your Apple ID.
Once the app has been copied to your device, you will need to choose to trust the app on your iPhone by navigating to Settings > General > Profiles & Device Management.
You should now be able to run the app on your phone and see the spinning ship. Congratulations!
The next step is to render your light field.