Game Development Reference
In-Depth Information
Chapter
2
Sprite Kit Scenes and SKNode Positioning
In the previous chapter I talked about what Sprite Kit was and how you can use it to create
2D games. I then jumped right in and showed how to start working with the
SKS-
priteNode
to create a background and player sprite and then showed how to add them to
a game scene.
In this chapter, I am going to step back a bit and give you a deeper look at Sprite Kit
scenes, including how scenes are built and why the order they are built in can change your
game. I will close the chapter with a discussion of Sprite Kit coordinate systems and anchor
points as they relate to
SKNode
s.
What Is an SKScene?
I used the
SKScene
object in the previous chapter to host the background and player
nodes, but I really did not explain the scene I was using. I just used it to add the sprites and
called it a day. It is now time to dig in and see how
SKScene
really works. I'll start by de-
fining an
SKScene
object.
An
SKScene
object represents a scene of content in a Sprite Kit game. An
SKScene
ob-
ject inherits from
SKEffectNode
,
SKNode
,
UIResponder
, and, of course,
NSOb-
ject
. It is constructed first by creating the scene and then by adding
n
number of other
SKNode
s to it. The scene plus all of its child nodes are called the
node tree
, and the scene
is the
root
of the node tree. The nodes contained in a scene provide the content the scene
will animate and render for display.
The following are the steps you performed in the previous chapter to create the node tree.
They are the basic steps you will complete whenever setting up a game scene.
1.
Create the
GameViewController
.
2.
Have the
GameViewController
create its
UIView
.