Game Development Reference
In-Depth Information
You now have a method that will create a new SCNNode for the floor. Next you need to
add it to your main scene so that you will be able to see and interact with this node. Head
back up to the viewDidLoad method, and after you create the main scene, add the fol-
lowing:
mainScenerootNode.addChildNode( createFloorNode() )
Run the game now, and you will notice that the spaceman is standing on a floor instead of
in the middle of nowhere, as shown in Figure 10-9 .
Figure 10-9 . Spaceman standing on the floor
This isn't that much fun and really doesn't show what Scene Kit is providing for you. So,
in the viewDidLoad() method, add the following line of code at the end of the meth-
od:
sceneView.allowsCameraControl = true
Run the game now, and you will be able to move the view's perspective, in other words, a
camera, around the object and see that you do have a 3D scene. You can do this because
you set the camera control to true . Use the pinch-zoom and panning gestures to move
around the scene. If you are running this in the simulator, notice the frames per second
(fps) and see that it is never near 60fps. On my simulator, it never gets above 20fps. This
time, run the game on your iPhone that has iOS 8 installed on it. Now when you move the
camera around, you should see the fps stays closer to 60fps. Does this mean your little
iPhone is more powerful than your Mac? Probably not. The simulator is simply simulating
the different devices to allow you as a developer to quickly test your code. However,
when you run the game on an actual device, you can see the power of Scene Kit. Scene
Search WWH ::




Custom Search