The one year game develpoment duel
May

15

2014

Learning Sprite Kit by Example

I hated school. I hate technical books. Generally, I feel like I can learn faster with the unstoppable trio of myself, Google and wonderful online communities. The trouble with game development is I don’t know what questions to ask. In web development, I can search how to make two elements sit next to each other and find what I’m looking for. In game development, I wouldn’t have looked for a finite state machine, much less double dispatch for physics. I may be late to the party compared to other developers, but I’m finding myself humbled by both books and open source projects that are extremely well crafted.

I thought it would be interesting to look at the 5 week path I took to becoming comfortable enough with Sprite Kit to have the confidence to make a game.

Intro to Objective-C / Sprite Kit Project

CartoonSmart provides a wonderful introduction to Sprite Kit. Coming from web development, the main goal at this point was to understand the syntax of Objective-C and the terminology of Sprite Kit.

How to Make an RPG

Sticking with CartoonSmart, I decided to purchase their tutorial on Role Playing Games with Sprite Kit. It helped that my game would be having role-playing elements, but this series also covered broad, important concepts like animation, attacking, movement, physics, and loading data through a property list.

Apple Adventure Game

About two thirds into the role-playing tutorial, I felt comfortable with the scope of that session. At this point, questions were popping into my mind. Should I preload assets? Should I use @property instead of an instance variable? I’ve only followed one teacher, but do they know everything or should I expand?

While I fully appreciate and recommend the CartoonSmart series, branching out and reading through the source of Apple’s Adventure project did reveal things like preloading, parallax, and more. It also allowed me to see how someone else might organize classes in their code.

Double Dispatch

At this point, I was happily working on my own project with both the CartoonSmart and Apple projects open. As I would implement a feature, I would reference both projects and decide on my preferred way of implementing it. Had I not referenced the Adventure Game, I would not have noticed Double Dispatch in the Apple Docs. And if I had not heard the term Double Dispatch, I would not have stumbled across this amazing open source project showing perfect example code: iOS-SpriteKit-Pong. Finding this project was a huge turning point for me. Prior to this, I did not believe reading through a random project on Github would be an effective use of my time. My general impression was that each project would be too specific, or too bloated to be of use. Turns out I was wrong, and there are plenty of gems out there.

Timer Class

With my new-found love of open source projects, I was on the lookout for what I could study next. I was trying to implement a timer for my tower defense game, and stumbled across the wonderful TCProgressTimer by Tony Chamblee. His code was clean and easy to read. It took less than an hour to modify it for my code base and having a working timer. It also introduced me to SKCropNode, which I was’t familiar with at the time.

Web Resources

Two extremely useful resources that have made their way around the web are Game Programming Patterns and Game Mechanic Explorer. Just reading through these two makes me feel smarter, and it opens up my vocabulary on what to look out for. It turns out I was using proper techniques semi-successfully but I didn’t know what they were called. After reading these resources, I began to recognize patterns and know how to search for more information on them.

Cocoapods

My growing confidence and love for other people’s code finally gave me the courage to install Cocoapods. This immediately paid off as I found a state machine for Sprite Kit called TransitionKit. I am not using TransitionKit in my project, but I did read every line of it thoroughly. State machines are complicated, and this process took almost a dedicated week of coding. I came out with a better understanding of Objective-C, coding patterns and my own home grown state machine.

I also found AHEasing and SpriteKit-Easing through this same process. It is tempting to move forward and implement the next visual feature, but just taking the time to slowly read through projects like these really does accelerate the learning curve.


 

As you can see, each great resource leads to another great resource. The amount of information and quality code out there is both inspiring and intimidating. I think there is a benefit in realizing how inadequate my code is for a task as long as I act on the realization. While it may be depressing to see 5 hours of work go down the drain, the payoff and education is worth it. If you’re in the same boat as me and learning Sprite Kit as a beginner, diving into other developer’s code is a hugely beneficial tool. My thanks to everyone in the open source community.

2 of you did not hold your tongue!
  1. This path looks cool, I am a total noob but feel inspired to have a look at the assets you have listed here.

  2. Thanks for putting this together, after a year of using Cocoapods at work, I will say that I vastly prefer Carthage: https://github.com/Carthage/Carthage It does the dependency management without messing with my project, or creating a workspace.


Speak Freely


Thank you

Your comment will be published once it has been approved.

Click here to see the pull request you generated.