Use Reference Nodes in Your Scene

Apple Game Frameworks and Technologies — by Tammy Coron (89 / 193)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Add a Camera to Track the Player | TOC | Add Support for All Devices a nd Orientations 👉

The SpriteKit framework includes a special kind of node known as a reference node, which is backed by the SKReferenceNode class. You create and use these nodes in your scenes when you want to reference the content saved in a different archived sks file.

With reference nodes, you can share content across multiple scenes without having to worry about unnecessary duplication. Because Val’s Revenge will undoubtedly include more than one level (scene), using reference nodes for certain content makes sense.

In the next section, you’ll use reference nodes to build a simple 8-way D-pad controller and the Attack button. Later, in Build Better On-Screen Controls, you’ll modify these controls to make them more robust, allowing the player to move and fire using 360° of rotation.

Creating the D-pad Controller Reference Node

Create a new file (⌥⌘N) using the iOS SpriteKit Scene template:

images/OperatingTheCameraAndUsingReferenceNodes/scene-editor-add-scene.png

Click Next and name the file Controller.sks. When the new file opens in the Scene Editor, you’re ready to get started.

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.