Creating an Age-Of-Empires-2-Esque Game for iPhone

Apprentice
Posts: 14
Joined: 2008.08
Post: #1
Hey there!

I've been thinking of making a game similar to Age of Empires 2 (one of my favourite old games) for the iPhone, and am a bit stuck on where to start!

I've been using JavaScript and PHP for about 2 years now, and started Objective-C/Cocoa about 4 months ago. So, preferably something using Objective-C would be welcome, as it doesn't mean I have to learn another language!

I've searched through this forum for some engines/methods to use, and they are all geared towards 3D games, which is far to complicated for what I need!

So, after a few days of searching, I've decided to register and ask you all if you have any advice.

I simply want to make an isometric-2D game, and need a starting point. I had a look at openGL, but it seems to be mostly for 3D games.
Are there any engines or something for this on Mac/iPhone, or do I have to start from scratch?

Any advice would be appreciated!

Thanks a lot! =)
Quote this message in a reply
Member
Posts: 245
Joined: 2005.11
Post: #2
On the Mac, the best way to do 2D games is often to use OpenGL. You just use your sprites as textures on 2D polygons and position them accordingly, with your camera set in orthographic mode. I haven't read any docs about the iPhone (but if I had I couldn't talk about it anyway), but I'd assume this is probably still true. CoreAnimation is probably too simple to be useful and the 2D routines in SDL are painfully slow if you want to do anything more advanced than pong. SDL may be OK if you use OpenGL for your graphics though. The iPhone uses OpenGL ES (version undisclosed as far as I know Ninja ) which works a bit differently to regular OpenGL.
Mind you, if this is your first game I'd try a few simple things to get the basics down before getting stuck into a big project. It's always more complex than you think and until you've tried and failed a few times you don't really get a feel for what engine architecture will work and what will turn into a horrible sprawling mess that is impossible to debug. Sad
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #3
AoE2 is one of my all-time favorites on the Mac! In fact, it inspired me to start working on a conquer-the-world type strategy game for the iPhone myself. In my estimation, the real-time strategy might be too hard for me to pull off right away, so I'm working on a turn-based one first, instead. Unfortunately, it's been a rough road getting it going so I've diverted to a simpler project for a few weeks to take a break on it for a bit.

So here's what I've learned about iPhone as far as graphics (which I think I can say without violating NDA, because I'm only talking about my own observed performance characteristics of publicly known iPhone technologies Sneaky ): Core Animation is awesome for relatively simple 2D stuff, and I think it should be preferred in simple situations for its battery efficiency (although you can make OpenGL battery efficient too if you handle your timers correctly). OpenGL is the way to go for anything requiring more performance than "simple". OpenGL ES is a little different than regular desktop OpenGL, but not nearly as much as I expected, and very straight-forward for general tasks -- no tricky stuff. The main thing to remember is that there is no immediate mode, so no quads for sprites, you must use something like a triangle strip from a vertex array instead, which is no problem in practice. Performance is "acceptable" I suppose. It's impressive for such a small device, but I was actually hoping for a little more, and maybe it's in there but I haven't found it yet. I can draw upwards of 18k-20k triangles at somewhere around 20 FPS (textured, lit, depth-tested). I've done absolutely every practical recommendation I could get my hands on for performance benefits (I don't dare say what those techniques are for NDA's sake), but that's as much as I've been able to squeeze out of it so far. But still, that's plenty enough performance, and then some, for an AoE2 clone. You can even do some nice 3D games with it.

Sadly, one *major* performance killer I've encountered myself is using too much Cocoa where performance is critical. I made one test application using nothing but Cocoa/Obj-C stuff for comparison and got only 20 FPS drawing around 4-5k triangles worth of objects (with texturing lighting and depth testing BTW). Then I re-wrote everything in 90% straight C and got 40 FPS for the exact same scene. I'm still using a little bit of Objective-C here and there for parts that aren't critically performance intensive. This wouldn't have been an issue at all on a modern Mac for that size of scene, but on the iPhone, things are quite a bit more limited, so it's something to keep in mind. So whereas on the Mac I'd use as much Cocoa/Obj-C as I can, on the iPhone I'm back to using a mix of Cocoa/Obj-C and straight C, which is fine with me.
Quote this message in a reply
⌘-R in Chief
Posts: 1,260
Joined: 2002.05
Post: #4
Jake: You could cache function pointers to methods you call a lot. Too late now, though I suppose Smile
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #5
You mean like using an IMP? Yeah, I thought about that but it's messy. Good reminder though. The big problem isn't really with Obj-C so much, and I still use it, but rather the speed problem is with Cocoa constructs such as arrays and dictionaries, etc., when used in performance critical tasks such as GL drawing. I've been really spoiled with those on desktop machines lately but there isn't really any way to make them magically as fast as bare-metal C on iPhone (that I know of).

There are compromises which can always be made, of course. I was describing the two extremes. Like I said, I used nothing but pure Cocoa for the test. That meant all numbers were stored as NSNumbers where it made sense, but I did use NSData for things that could be sent to the GL as a vector quantity, such as a material color or even geometry data and indices. But most killing of performance (I'm guessing) was probably that I did everything with dictionaries and NSArrays. So there were no specialized classes which handled themselves, as one might do in practice -- everything was stored in a generic Cocoa primitive. The point of my test, for myself, was to gauge how much Cocoa I could use on iPhone. The answer is: as much as I want for non-performance-critical operations. So even now I still sprinkle it in, and still use Obj-C until I find a spot that needs optimization. From my test, optimization is definitely needed more often on iPhone, mostly because pure Cocoa appears quite expensive, compared to desktop machines where I hardly pay attention anymore.

Just to be sure, I should clarify that I'm not suggesting not to use Cocoa or Objective-C on iPhone, just that Cocoa is expensive on iPhone if you're not careful where and how you apply it when writing OpenGL stuff.
Quote this message in a reply
⌘-R in Chief
Posts: 1,260
Joined: 2002.05
Post: #6
Roger. Roger.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Need help in creating a memory game(2) soulesstps 9 6,900 Dec 13, 2010 07:44 PM
Last Post: soulesstps
  Need help in creating a memory game soulesstps 12 8,613 Dec 4, 2010 11:58 AM
Last Post: shazi
  creating a game background problems chrism 6 3,894 Jun 6, 2009 06:58 PM
Last Post: chrism