Do Yourself A Favor. Use SpriteKit.

Ben Kimble
devslopes
Published in
7 min readFeb 23, 2018

I really hope my wife doesn’t catch me, I thought to myself as I nervously glanced over my shoulder. I’d been developing iOS apps for about a month and had the thought “I should check out this game thing.”

I’d seen the game option when I was creating new projects and figured I’d check it out. Having used other game engines, the mechanics were familiar enough. The built-in animator worked well. Controlling animations was simple. But even with all of that, why was I sitting here at 3am in the dark playing with this thing? I knew if my wife woke up and realized I was still sitting in front of my computer, I would be in trouble.

I started thinking about it, and after about 10 minutes I came to my conclusion. My personal apps sucked. Not the ones I was learning to make from the Devslopes team, but my own personal projects. My apps just felt… I don’t know… lifeless? I wanted them to move. I wanted them to think. After working on a game, my apps just felt dumb.

SpriteKit has been around for awhile, but it’s really underutilized. Some developers are overwhelmed because it seems so different from what they’re used to in iOS. Some think it’s a games-only tool. Some just don’t realize it’s even there. So what can SpriteKit do for your iOS or tvOS project?

So What Is This “SpriteKit” Thing?

SpriteKit is a framework for iOS and tvOS which allows us to easily build games in Xcode with Swift and was released around 2013. It comes out of the box with a physics engine, animation handling, particle systems, and a built in shape creator. It’s also got a system for timing and automating sound and visual effects.

You get it. It’s the whole package. On top of all of that, it’s really easy to use if you’re familiar with iOS development. Everything has an event, just like any other app would. And since it’s built by Apple for Apple, you can be pretty sure you won’t have any wildly unexpected behavior from device to device. The idea behind it, simplified, is to add a game loop layer on top of a normal app.

Under the hood, SpriteKit renders to the screen the same way a banking app would. It just gives us a (considerably large) toolset to make that app look awesome. Oh, and game-ish. At the time SpriteKit was released that toolset was pretty revolutionary. Since then, it’s gotten so much better. “But, but…. Unity3d…. Unreal Engine 4…. <Insert your favorite game engine here>”.

I know, I know. They have many of the same features SpriteKit has and then some, but it’s important to remember that everything is a tool for a job. There are a lot of reasons to use SpriteKit over another game engine, depending on your situation.

Okay, Why Should I Use SpriteKit?

Like I said, tool for the job. Every situation is a little different. So let’s talk about some reasons I can think of that you would want to use SpriteKit:

I LOVE coding in Swift. It’s the only language for me.

Point taken. Swift is an awesome language. I hadn’t used it until just before we moved from Swift 3 to Swift 4, and I was converted immediately. I love lots of game engines so I can’t be monogamous with Swift. But if other game engines *cough* Unity *cough* would adopt Swift as a scripting option I would be all over it in a heartbeat. And there’s something to be said for really mastering a language and diving deep into it.

I want to make a high performance 2D game in the Apple Ecosystem.

Game engines that are cross-platform are a gift from the Gods. I’ve written games from scratch before without their help. Once. That was enough for me. I love game development, but I questioned it during that phase in my life. I have immense amounts of respect for the pioneers of our industry who used to do all of that by hand or write their own engine for it.

The problem with these cross-platform engines, though, is that in every transpilation (translating and then compiling) process ever there are inefficiencies. Things get lost in translation and your game slows down a little bit. We gain the convenience of not dealing with a dozen different operating systems by giving up a bit of speed and power. It’s the law of equivalent exchange. So if you’re building a game you know is going to be intensive, do some benchmarks and consider SpriteKit as an option to avoid some of that. If you want to get really intense there’s always Metal, but that’s a different topic.

I only want to target Apple products like Apple TV, iPhone, or the iPad.

If your only targets are in the Apple family, I’d suggest going with SpriteKit over another engine. It’ll save you a lot of incompatibility and configuration problems down the road.

I want to gamify my app.

You have an app you want to make even cooler? Great. You could add a small game while your app is loading large bits of data, or waiting for a connection or event. Ever been without internet with Google Chrome open? Something like that. You could add a game animation to buttons or other controls. You could use SpriteKit to have an animated movie-style background. You can interact with other components using SpriteKit. Hybrid apps between UIKit and SpriteKit are easy to set up and I personally love them. There are endless possibilities here.

I want to get a rapid prototype of a game out, and the best platform for that in my case is an Apple product.

SpriteKit makes animations easy. They make user interactions even easier to set up. Even if you want to use another engine, SpriteKit could help you out. I’m a huge fan of prototyping. Nothing is more disappointing to me than spending 40+ hours on a game just to find out it’s boring. Having done that a few times, I’d suggest prototyping everything before you start polishing. Users don’t need pretty graphics and effects to find out if the game is fun or not. Of course I’m against releasing unfinished products, so a game should never stop at a prototype (unless it just sucks and you’re abandoning it). Using Spritekit, you can add animations like movements as easily as grabbing a sprite node variable and telling it:

let moveNodeUp = SKAction.moveBy(x: 0.0, y: 100.0, duration: 1.0)
rocketNode.run(moveNodeUp)

I’m new to game development and just want to dabble a bit.

Welcome to game development! It rocks and I love it. If you’re familiar with iOS development or Swift, then SpriteKit is a great place to dive in and dabble. You can learn the basics of game physics, game loops, event handling, and everything else you’ll need to know playing with this framework. If you already know how the language running the show works, that means you can just focus on learning how to make your idea come to life.

Other game engines are just so….. Bloated.

It’s true. Things have gotten a lot better compared to, say, 5 years ago. But no matter what, any transpiled game engine is going to have a bit of overhead. By using SpriteKit and only importing what you really need, you can save a fair amount of space on the user’s device. While that’s not as big a deal now, we always want to be aware of the footprint our games or apps have and respect the user’s memory. It’s theirs, not ours.

Alright, I’m Convinced. SpriteKit is Okay, I Guess. Now What?

Now you just get started. SpriteKit is really easy to get up and running. If you’ve ever started an iOS app, you’ll be familiar with the following screen. Instead of clicking “Single View App” or any of the other options, just choose “Game”.

Then give your project whatever title and metadata you want, as well as these settings:

If you’re just starting out, it’s probably best to leave GameplayKit out of it until you have a better understanding of the system. Feel free to include unit and UI tests in as well, just know they’re not mandatory. After that, feel free to play around in the pre-built game scene, “GameScene.sks”.

What, you want more details than that? Well lucky for you we’ll have some content on that shortly. Devslopes’ Apple Slope is going to have some content coming at it in the near future with all of this information and so much more. We’ll walk you through your first game, show you how to handle animations, teach you to use SpriteKit’s game loop and physics engine, and everything else you need to know to start bringing your game idea to life.

If you want to learn more about Swift and iOS development, head over to www.devslopes.com and enroll in our Apple Developer Slope where you’ll learn everything you need to know to develop iOS apps. ❤️

--

--

Ben Kimble
devslopes

Game and Blockchain Developer. I also teach people how to code sometimes.