Game Development Reference
In-Depth Information
Chapter
15
Using Sprite Kit with a Scene Kit Scene
In the previous chapters, you worked within the Scene Kit paradigm; however, Apple has
created a way for you to add a 2D scene to overlay on your 3D scenes. In this chapter, you
will add a 2D scene that will be used for your timer so it can track how long it will take you
and your friends to find and capture the enemy.
Sprite Kit Integration
Scene Kit gives you a property to add a Sprite KitSprite Kit scene.
var overlaySKScene: SKScene! { get set }
This property can render a 2D scene that overlays the Scene Kit scene. To provide better
performance, Scene Kit and Sprite Kit use the same OpenGL context and resources to
render the scene.
For this game, you will add a scoreboard to the top of the scene, as well as the amount of
“lives” the user has left. To get started, create a new Swift file and name it GameOver-
lay.swift .
Now that you have the file created, you will need to import both Scene Kit and Sprite Kit.
import SceneKit
import SpriteKit
class GameOverlay: SKScene {
}
Your class should look similar to this code snippet. Your GameOverlay class is a subclass
from the SKScene, which should look familiar from previous chapters. For this class you
will add a node for the score and another one to keep track of the player's lives.
Search WWH ::




Custom Search