Using Sprite Kit to Animate a Scene

Login to Access Code

In our previous post, we covered some of the core components of Sprite Kit that are relevant to many games: SKView, SKScene, and SKNode. In this tutorial, we will use each of those components to render a scrolling landscape and hero figure that runs across the land.

Create the Sprite Kit Game from a template

First we need to create the project. In Xcode6 we will create a new Game by selecting the File menu > New > Project and select “Game” from the iOS templates.

Next we need to name our project and make sure we select Swift as the language for this project. For ours, we’re naming it “Run Fast”

Add SpriteKit Image Assets

You should see some view templates with the template project. You can run it as-is to verify that everything is working which should show you a “Hello World” app which responds to touches on the screen to add spinning spaceships. Our next step is to add our own custom image assets (which you can retrieve from the git repository).

If we select the Images.xcassets under the Run Fast folder/group in Xcode, we can add our custom image assets here by drag-and-drop from finder. We are going to add the various frames for our hero:

and then we’ll also add the ground image assets:

Now we’re going to simply replace the default GameScene contents with our custom code. The code should be mostly self documenting, but if you have questions or issues, feel free to comment on the Gist source on Github.

https://gist.github.com/304d5edb39ed22c243d2.git

You should now have a running app!