Game Development Reference
In-Depth Information
Node types
There are different node types that serve different purposes:
•
SKNode
: This is a parent class for different types of nodes
•
SKSpriteNode
: This is a node that draws textured sprites
•
SKLabelNode
: This is a node that displays text
•
SKShapeNode
: This is a node that renders a shape based on
a Core Graphics path
•
SKEmitterNode
: This is a node that creates and renders particles
•
SKEffectNode
: This is a node that applies a Core Image filter to
its children
Each of them has their own initializer methods—you create one, add it to your scene,
and it does the job it was assigned to do.
Some node properties and methods that you might find useful are:
•
position
: This is a CGPoint representing the position of a node in its parent
coordinate system.
•
zPosition
: This is a CGFloat that represents the position of a node on an
imaginary Z axis. Nodes with higher
zPosition
will be over the nodes that
have lower
zPosition
. If nodes have the same
zPosition
, the ones that
were created later will appear on top of those that were created before.
•
xScale
and
yScale
: This is a CGFloat that allows you to change the size of any
node. The default is 1.0 and setting it to any other value will change the sprite
size. It is not recommended, but if you have an image of a certain resolution,
scaling it will upscale the image and it will look distorted. Making nodes
smaller can lead to other visual artifacts. But if you need quick and easy ways
to change the size of your nodes, this property is there.
•
name
: This is the name of the node that is used to locate it in the node
hierarchy. This allows you to be flexible in your scenes as you no longer
need to store pointers to your nodes, and also saves you a lot of headache.
•
childNodeWithName:(NSString *)name
: This finds a child node with the
specified name. If there are many nodes with the same name, the first one
is returned.
•
enumerateChildNodesWithName:usingBlock:
: This allows you to
run custom code on your nodes. This method is heavily used throughout
any Sprite Kit game and can be used for movement, state changing,
and other tasks.