Chapter 7. SpriteKit
The SpriteKit framework was first introduced in iOS 7 and OS X 10.9, and because it is designed purposely for creating games, it is heavily optimized for rendering and animating 2D graphics.
At its core, SpriteKit is a simple, object-oriented toolkit for drawing sprites (i.e., images and text) that provides you with significantly more flexibility and performance than using UIKit for the same purposes, while at the same time not forcing you to go down to the level of writing OpenGL code.
In addition to its graphical features, SpriteKit also comes with a built-in 2D physics engine, which handles collision detection, collision resolution, and rigid-body simulation.
In this chapter, you’ll learn how to create SpriteKit scenes, how to work with sprites and shape nodes, as well as how to take advantage of new features added in iOS 8.
At the high level, SpriteKit is all about nodes. There are three things to know about nodes:
- Nodes are contained within a SpriteKit view.
- Nodes can have other nodes as their children.
- Nodes render graphics into the view (depending on their type).
SpriteKit nodes are all instances of
SKNode, or one of its subclasses. There are a lot of different subclasses: at its base, the empty
SKNode class represents an empty, invisible node, while
SKSpriteNode represents an image or colored rectangle,
SKShapeNode draws a Bézier path,
SKEffectNode applies image effects like blurs or tints on its children, and more.
When you want ...