Game Development Reference
In-Depth Information
Table 1-2
.
The Descendants of SKNode That Render Visual Elements
Class
Description
A node that is used to draw textured sprites
SKSpriteNode
SKVideoNode
A node that presents video content
SKLabelNode
A node that is used to draw text strings
SKShapeNode
A node that is used to draw a shape based upon a Core Graphics path
SKEmitterNode
A node that is used to create and render particles
A node that is used to crop child nodes using a mask
SKCropNode
SKEffectNode
A node that is used to apply Core Image filters to its child nodes
In this topic you will be using three subclasses of
SKNode
:
SKSpriteNode
,
SKLa-
belNode
, and
SKEmitterNode
.
After adding the two
SKSpriteNodes
, add the following lines to the bottom of the
GameScene.init(size: CGSize)
method:
// adding the background
backgroundNode = SKSpriteNode(imageNamed: "Background")
backgroundNode!.anchorPoint = CGPoint(x: 0.5, y: 0.0)
backgroundNode!.position = CGPoint(x: size.width / 2.0, y:
0.0)
addChild(backgroundNode!)
The first line of this snippet creates an
SKSpriteNode
with an image named
Back-
ground
, which you just added to your
Images.xcassets
folder.
In this case you are drawing the background image. The next line of code determines
where the new node will be anchored in your scene. Don't worry too much about this at
the moment. I will be discussing anchor points in great detail in the next chapter. Just
know that the anchor point of (0.5, 0.0) sets the anchor point of the background node to
the bottom center of the node.
Next, you set the position of the
backgroundNode
. Here you are setting the node's po-
sition to an x-coordinate half the width of the scene, which is in the middle of the scene,
and setting the y-coordinate to 0.0, which is the bottom of the scene.