Draw SceneKit content in a SpriteKit scene by using a 3D node.
SceneKit content rendered in SpriteKit is automatically assigned a camera and, because
autoenables defaults to
YES, lights. That means you require very little code to add simple 3D primitives to your scene. The following code shows how to create a simple scene containing a torus and display it in a SpriteKit scene.
After node is added to a
SKScene, the 3D torus is visible:
Control How Your Content Is Rendered
SK3DNode creates a default camera automatically, you can create your own camera for precise control over how the 3D content is rendered. The following code shows how you can create a 3D node with an explicitly created camera that looks at the first object in the SceneKit scene's node tree.
Set the Position and Orientation of Your 3D Content
You can create many instances of
SK3DNode, each sharing the same SceneKit scene but each with an independent point of view. By updating the position of each 3D node's point of view, you can create code that simulates a top-down, one-point perspective view. The following example shows how to do this by enumerating over all the nodes named
3dnode in the
update method of a
The following image shows how this code gives the impression of perspective inside SpriteKit: