2D Game Engine Tutorial

Quick note: I’ve started an indie game studio!

I haven’t had time to write any more blog posts just yet, but that’s because of something very exciting! I’ve recently started Fou Games, an indie games studio. If you’ve found anything here helpful, you can support me by liking us on Facebook, following us on Twitter, or subscribing to our newsletter.

The Tutorial Series

To build Galaxy Wild I wrote my own 2d game engine, Tau Engine. That project is open source and I encourage you to look at it and evaluate its usefulness for your own next game (or use Cocos2d, a mature game engine with a large community behind it).

But building a game engine from scratch helps you learn what’s going on under the covers, lets you experiment with new techniques or effects that an off the shelf engine doesn’t support, and it’s fun to do. This tutorial will give you the skills necessary to build your own simple 2D game engine.

The game engine built in this tutorial is based on GLKit in iOS5, but with a bit of extra effort and programming experience you could follow along in any language with OpenGL bindings. GLKit was chosen because it provides a plethora of convenience methods that reduce the amount of work necessary to get started rather substantially. While it’s always preferable to have deep knowledge of the technologies you’re working with, visible progress creates the interest and positive feedback that sustains learning—starting here provides a gateway into the deeper topic of OpenGL ES. Also, I like Objective-C more than C++.

The tutorial is broken up in to several parts:

  1. How to set up a GLKit project
  2. How to set up a 2D scene
  3. How to draw 2D shapes | Part 2
  4. How to color objects
  5. How to texturize objects | Part 2
  6. How to manipulate objects
  7. How to render multiple objects
  8. How to create and render composite objects
  9. How to animate objects | Part 2 | Part 3

In the future, I may extend this tutorial to include the following lessons:

  1. How to manage scenes
  2. How to do 2D collision detection
  3. How to integrate a 2D physics engine

All of the source code is available on Github to peruse or use as a foundation for your own game engine.

git clone git@github.com:ianterrell/ExampleEngine.git
cd ExampleEngine/

Periodically in each article I’ve tagged the repository so that a snapshot of its current state is saved. The tags are noted in the articles with the following icon and link to the repository:


To set your repository to that state, from the root directory you can check out that tag like this:

git checkout tagname


This tutorial was developed against the iOS5 beta SDKs. The code in these posts and the repository’s HEAD have been updated as the SDK has been updated, but the example repository’s early tags won’t build with the final SDK. The following changes can be applied one by one if you need them:

  • Iterations 9-16 use the texture API from beta 5. The changes required are simple, and are in 04d7980.