How to display a Scene in SceneKit

A Brief Introduction

Edoardo Troianiello
2 min readOct 14, 2022

SceneKit

If you are thinking of creating a 3D game for any Apple device, you can rely on SceneKit. It works a lot like its 2D brother SpriteKit, with some important differences.

Scene

The whole action will happen inside a Scene, that is a container for the elements that will populate your game. These elements are called nodes.

Nodes are contained in a hierarchical way where the root node (on top) defines the world’s coordinates. This structure is called Scene Graph.

SceneKit, being a 3D framework, has a coordinate system based on 3 axes: x, y, z. By default, it is a right handed system.

Displaying a Scene

To be able to display a scene you must assign the scene to the property scnView.

Other than nodes, a Scene contains a lot of useful methods to control the game flow, like play(), stop(), or pause().

XCode is also provided with a simple and intuitive 3D editor which allows you to create your scene and position all the basic shapes and other assets visually inside your world without the need to write a single line of code.

Nodes

A node is a structural element of the scene graph. It has defined properties to manage it such as geometry, position and so on.

SceneKit also provides you with some special nodes like a camera node or a light node to handle your scene easily.

Once defined, a node can be added to the root node with the method .addChildNode(SCNNode).

Useful Tips

scnView has some methods that can be used as utility tools to simplify the development of your game.

  • showStatistics displays various information about the rendering performance, GPU resource usage and a frames-per-second (fps) counter
  • allowCameraControl allows you to manipulate the point of view used to render the scene (useful for positioning elements)
  • debugOptions = SCNDebugOptions.showPhysicsShapes outlines all elements on the scene, useful when you have to work with invisible elements (like collision boxes)

SceneKit can be very useful to create all kinds of 3D games, this is just a starting point, hope you enjoyed it!

You can also check out this iPhone game made solely on SceneKit: https://apps.apple.com/it/app/sushiroll-il-gioco/id1610765239

Authors:

Andrea Masturzo, Edoardo Troianiello

If you enjoyed this article, please click the 👏 button and share so that others can find it! Feel free to leave a comment below. More articles on the topic are yet to come follow us!

--

--

Edoardo Troianiello

Computer Engineer | iOS Developer | Alumni @Apple Developer Academy in Naples