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:
- How to set up a GLKit project
- How to set up a 2D scene
- How to draw 2D shapes | Part 2
- How to color objects
- How to texturize objects | Part 2
- How to manipulate objects
- How to render multiple objects
- How to create and render composite objects
- How to animate objects | Part 2 | Part 3
In the future, I may extend this tutorial to include the following lessons:
- How to manage scenes
- How to do 2D collision detection
- 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 email@example.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.