Now we are going to look at using Physics in our Spritekit based game. If you’ve worked with a physics engine before, a lot of this is going to feel very familiar. One of the key differences from many other engines is SpriteKit handles updating the graphics as well as the physics. It’s a fairly involved process, so I am going to split this across multiple posts.
Back in Part 3 of this SpriteKit/Swift tutorial series we looked at loading game sprites using a texture atlas and implemented a simple animation system. At the time I said this wasn’t the way you perform animation and that I would cover the proper way later. Then in Part 4 we covered SpriteKit actions showing how to perform a number of different actions. Now we look to combine the two, using actions to perform sprite sheet based animations using a TextureAtlas.
Now that we’ve tackled the basics of graphics, let’s take a look at making our game “do” something. This is often the job of SKActions, so let’s jump right in with a simple example. Just like in the last example I am going to use the basic project structure we established back in the very first post. All code samples are going to be in the GameScene.
In the previous tutorial part we looked at working with a single Sprite. Reality is, very few games are composed of singular sprites. UI’s are made up of a number of different sprites, animations are composed of several different frames, each composed of a single image. Loading hundreds of individual textures is not good for performance. A very common solution is to use a texture atlas ( or sprite sheet ). Fortunately Xcode make it extremely easy.
As you can imagine by the name “SpriteKit”, Sprites are a pretty core part of creating a game using SpriteKit. We are going to continue building on the minimal application we created in the previous part. I want to point out, this isn’t the recommended way of working with SpriteKit, it is instead the simplest way. In a proper application we would be more data driven and store our data in SKS files instead of simply adding them to the project. This is something we will cover later on.
With Apple’s recent release of the Swift programming language I have decided I have to check it out. One of the biggest reasons I’ve stayed away from Apple’s various SDKs is my dislike of Objective-C. Swift on the other hand is quite a nice little language at least from my experiences so far.