Learning SpriteKit

I’ve always admired gaming for the way it pushes boundaries of hardware and software, but didn’t think I would want to actually be a games programmer because the technology was low level and not relevant to my professional work. SpriteKit changes this with a framework that is approachable and well integrated with the standard Apple libraries for building on iOS.

The SpriteKit project should be familiar to anyone with experience in Xcode, as it appears the same as any other iOS project with the familiar AppDelegate, ViewController and Storyboard. A key difference is that the ViewController hosts an SKView instead of a UIView. This SKView is responsible for launching game scenes, with the presentScene method. This is the point where SpriteKit takes over and where the Developer will spend their time.

Each scene requires some kind of background image and for my learning I approached the 2D nature of SpriteKit from a top down point of view. A birds eye view into an imaginary world. The background is a series of tiles, much like a chess board, with each tile being uniquely identified and having characteristics that make it walkable (or not) by the player. A Path finding algorithm is used to navigate the player when the user touches the screen.

The heart of SpriteKit is the SKScene run loop which renders up to 60 frames per second. Each iteration of the loop triggers the following method calls in the SKScene (update, didEvaluateActions, didSimulatePhysics and didFinishUpdate). The developer leverages these methods to reposition elements in the game, play sounds, set off explosions and anything else you might like to see in the game!

SpriteKit is tightly integrated with UIKit, so it’s very easy, using the familiar delegate pattern, to pass control from the game scene to the ViewController, where UIKit elements like modal views can be displayed. This allows elements like a heads up display to be built entirely in UIKit, using typical controls like buttons and labels. The screen shot below shows the early stages of a SpriteKit game, with source code available in my Bitbucket Repository.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s