Cocos 2D and Me

Selecting an iPhone Games Engine

by Ben on Feb.01, 2010, under General Games Development

You may have heard the term “game engine” before, but never paid much attention to what it means. Game engines are generally libraries of code designed to do a lot of the hard work in creating a game. Most modern game engines are impressively comprehensive, and can include simple things like loading images and moving them around, to more complex ideas such as designing and laying out levels. There are already several game engines for the iPhone, and with all the conflicting information available online, selecting one is confusing at best. As you may have already guessed from the name/URL of this blog, I’ve already made my decision, but that doesn’t mean you’ve made yours. I also feel it’s important to know what else is out there, as a wise coder always knows what options they have, rather than how to do everything with one option.

Our Criteria

As this will be my first game, I’m going to stick with the KISS principle. Like many of you, if I make things too complicated for myself I’m going to lose heart and eventually give up. So, here’s a few points of what I’m after in a game engine, and what sort of game I want to develop:

  • I’ll be making a 2D game. Adding that third dimension adds a whole new layer of complexity, and I have no idea how to deal with 3D models. Flat images I can deal with.
  • I don’t want to create a puzzle game. This is simply a matter of choice, as I want to be excited by what I’m developing. Puzzle games are fun, but they don’t excite me.
  • I want to understand what I’m doing. So, I’m not looking for a super high level engine which allows me to do everything quickly, but is impossibly hard to tweak once I want to do anything unusual – which is bound to happen.
  • The engine I select needs a good support network. Whilst there are some really great libraries out there, without any documentation or support they’re going to have a very steep learning curve.

And that’s about it. Let’s move on at take a look at what I consider to be the main options available for an iPhone game engine.

Core Animation / Core Graphics

Core AnimationThe Core components included in the iPhone SDK are, believe it or not, capable of powering a game. If you do enough reading on this topic, you will find many people who tell you you are wasting your time by developing a game using only the standard libraries, and to some extent this is true. As the standard Core libraries aren’t really built for developing games, they do have limitations. If your game is a simple puzzle type game where only one or two things are moving onscreen at a time, the Core libraries can be a good choice. They’re built-in, they’re free, and they’re using the language you are probably already used to, Objective-C, so there’s not much of a learning curve. There’s also going to be plenty of Apple documentation and support. The downside is that performance is going to be a problem if you start to do anything complicated. There’s a good example of developing a game using the Core libraries here.

OpenGL

OpenGLOpenGL is pretty much the standard games engine for a large number of platforms, including the iPhone. It is incredibly powerful, well supported, and used in a huge number of modern games. Unfortunately, OpenGL is a pure C framework that it is not particularly intuitive, particularly for a beginner. It has been around for a very long time, and as such can feel archaic and bloated – many lines of code are required just to display a simple graphic onscreen. For those willing to invest the time and dedication, OpenGL can be a fantastic platform, but for my purposes I believe it is not a good choice. There are other libraries around which use the power of OpenGL, but provide a higher level development experience.

Torque

Torque 2D for iPhone has been developed by the well known company GarageGames. Torque has been released for many different platforms, and as such has a long solid history and is quite a popular choice. If you are planning on building a 2D game, Torque would be a good choice. It offers a visual game builder, and includes the full source with the package in case you want to make any modifications yourself. Torque also provides an easy way to port your games to other platforms, such as Xbox360 or Wii. The main reason I personally would not use Torque at this time is that I feel there’s too much of a learning curve. Torque uses it’s own scripting language, so you won’t be coding in Objective-C, and having never had any experience with game builders such as this I fear I am too far out of my depth. I don’t feel comfortable building everything with drag and drop and scripts, I want to write some actual code! Other downsides include the cost, and needing to have a “developed with Torque” splash screen displayed when launching your game (if using the indie version). However, if you think scripting and drag-and-drop appeals to you, it might be worth giving one of the demos a try, though from memory there’s no specific iPhone Torque demo available.

Unity

UnityUnity is another drag and drop type game builder, and as such is seen as a direct competitor to Torque. Unlike Torque 2D, Unity supports both 2D and 3D games (Torque 3D for iPhone is coming though, sometime). The advantage of this is obvious, providing more flexibility in the type of games you can create. Unity also provides scripting features, but this time in C# and Javascript, so is more likely to appeal to more people. Unity reportedly also has much better documentation and support than Torque, so if I were to choose a visual game editor such as this, Unity would probably be my choice. The main reason I have not chosen Unity is that it is really a 3D game engine. Whilst 2D games certainly can be built with it, I believe this will add another layer of complexity which I just don’t need. Unity also has costs associated with it, and has the same splashscreen requirement for the cheaper version. If you do decide Unity is down your alley, there should be a demo for the iPhone available, and a great set of tutorials to get you started here.

Cocos2D

So, finally we get to Cocos2d for iPhone. Cocos2d is an open source framework built specifically for creating 2D games, which has been ported to iPhone. It has some really nice effects which you can see in the video demos, and gets some great reviews for people who are using it. All code is written in Xcode in regular Objective-C, so anyone who has done some iPhone development already should feel comfortable with the syntax at least. The catch is that documentation is sorely lacking. After a few hours of searching I only managed to come up with a small collection of articles, half of which are already out of date, so there is more of a learning curve than I was hoping for.

The Winner – Cocos2D

So, obviously I’ve chosen to go with Cocos2d, but why? Well, it fills most of my criteria. It’s specifically for 2D, so we’re keeping things simple – I don’t picture myself working on 3D games anytime soon, and I expect when I do it will be as large a jump from 2D games to 3D games, as it will be from apps to 2D games, so I don’t want to make two jumps at once. The demos are pretty convincing as to the capabilities of the engine, and writing code in Objective-C makes me feel confident enough that I will be able to understand everything that’s going on in my project. To me, Cocos2D feels like a comfortable middle ground between the low-level Core & OpenGL libraries, and the high-level Torque and Unity frameworks. Although the documentation is not as good as I would like it to be, there are active forums and Cocos2D is growing rapidly in popularity. It’s with this blog that I’m hoping to help fill the documentation hole, and provide a useful set of tutorials for people who are in the position I’m in now.

If you still haven’t made up your mind, there are some other options. Oolong, GameSalad, and Shiva are all iPhone game frameworks, but I felt they weren’t mature enough to consider seriously. Who knows though, by the time you read this entry they might be! If you’re not a big fan of Objective-C and are looking for something higher level, this thread gives some useful insights into the merits of both Unity and Torque. Finally, if you’re still feeling like you want to go with OpenGL or the Core libraries, I’d strongly recommend you keep an eye on this blog – I’m positive Cocos2D has a lot to offer you.


Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...