5 May 2010

5 Things I Learned Making My First iPhone Game

 

Tomato-San says: w00t, it's done!

Tomato-San says: w00t, it's done!

I’ve been in hibernation for the last few weeks putting the finishing touches on my first iPhone game – but now I’m back, since the game is finally on the App Store!

For the curious, the game is called Math Ninja and is an educational iPhone game designed to make practicing addition, multiplication, division, and subtraction fun. It’s actually based on the How To Make A Simple iPhone Game with Cocos2D Tutorial Series from this site, and the art was done by my lovely wife!

Anyway, in the process I learned a ton of lessons about making games that I thought you guys might find interesting. So here’s what I learned from the whole experience!

1. It’s OK to Rewrite

The first time I wrote Math Ninja, the code was pretty bad. Spectacularly bad, I might say. I was new to Cocos2D, so made a lot of rookie mistakes, and had designed the app as I was writing it, so the organization was pretty ugly and full of hacks.

So I had a dilemna halfway through the project – should I wrap up the game as-is, figuring the end user would never know the difference anyway? Or should I rewrite it from scratch now that I knew what I was doing better – and add some improvements along the way?

There’s actually a lot of debate on this subject. Joel on Software calls rewriting software from scratch the single worst strategic mistake that any software company could make.

I debated the subject for a while, and finally decided to go with the rewrite – mainly for self-satisfaction and learning sake. The rewrite took me about half as long as it took me to write Math Ninja the first time, so was quite time intensive. So was it worth it?

In this case, definitely. I think it was worth it for the following reasons:

  • In general, the game rested on a much firmer foundation, making it much easier to add new features.
  • During the rewrite, I refactored the level design logic out into an easy configuration file, which was made the game design much easier (more below).
  • During the rewrite, I put more thought into how to store and save game state, which made loading and saving much easier.
  • During the rewrite, I put more thought into game performance, making the app more responsive.
  • And perhaps most importantly, I was personally much happier with the results and can be proud of it (instead of feeling slightly guilty!) :]

I think my key takeaway from this is when you are learning a new library or way of constructing software, the first time through you’re going to make a ton of mistakes. You can refactor along the way, but with games you are constantly changing things until you figure out what is fun.

So it’s very difficult to maintain the pace of constant refactoring (for cleanliness) with constant refactoring (for fun), while at the same time learning a new library (at least for me). So rewriting let me get additional development speed during the “prototype” phase in tradeoff for additional development time later (to rewrite).

In the future, I think it would be even more useful to make a prototype in a language more suited for rapid development (such as perhaps Flash or Cocos2d Python) to get the game design elements worked out, then switch over to Cocos2D-iPhone when the game design look solid/fun.

2. Make Game Design Easy As Possible

The first time I wrote Math Ninja, the game design was literally hard-coded into my game. To change the health of monsters required changing a number in the constructor of the Monster class. To change the monsters that spawned in a level required writing some code in a function. And so on for weapons, story elements, etc.

It wasn’t hard to tweak these settings, but the amount of switching between files/lines of code necessary to effect a change added up – and subconciously, made me not want to change certain game design elements out of laziness.

This is a bad thing. In order to feel complete freedom to change the game design elements such as monster stats, level spawns, etc., editing those needs to be as easy as possible.

So in the rewrite, I pulled all of the definitions for monsters, levels, story, etc. out into an easily tweakable XML file. I started to build a WPF editor for the XML file, but then I realized that editing the XML by hand was much easier and faster than any editor could be and just stuck with the XML.

Of all the changes I made, making the game design aspects so easy to tweak was probably the most important. Here’s why:

  • Since changing game design aspects was so easy, I felt free to make any changes required to make the game more fun/balanced.
  • Testing was much easier. I could easily create levels to spawn certain monsters or combinations I was working on.
  • There was a clean separation between game design aspects and programming aspects. This helped me mentally get in the right “state of mind” for each task – which feel very different for me!

3. However, Game Design Is Still Hard

The other thing I learned was no matter how easy you make it to tweak your game design, coming up with a good design is still incredibly hard and time consuming work.

I don’t even know how many times I changed the effects, damage, and upgrade paths of the various weapons in the game, or played each level in various difficulties with varioius weapon choices.

At first I felt strangely guilty even spending all this time on game design. To me as a programmer, spending so much time on the game design felt like “playing” or “goofing off” when I really should be coding :]

But then I realized that logically, getting the game design right was probably the most important aspect – after all, that is what makes the game fun – so was worth the time.

I realize I still have a lot to learn from game design. I think experienced game designers use a lot more math and spreadsheets than I did, calculating average DPS, max damage possible per time frame, etc. to figure out the right damage for weapons/upgrades/etc.

Being a beginner, the only way I knew how to do it was by iterating, iterating, iterating until something good came out. It worked (at least I hope so) – but just took a lot more time and hair pulling!

4. Yes, You Need Testers!

Toward the end of wrapping up the game, my wife and I were pretty happy with the result, to the point where we started saying stuff like “Meh, we don’t need testers, our game is awesome, what could possibly go wrong?!”

Little did we know.

Luckily we enlisted the help of some friends and family (including my three awesome cousins Drew, Blair, and Ry) with wide age ranges and skill levels, and had them try out the game. And they discovered bugs – lots of them – that would have been embarassing to have shipped with!

Not only that, but they gave us a lot of great ideas too!

So lesson learned – no matter how good you think your app/game is, get some testers. You won’t regret it! :]

5. The Last 10% Is The Hardest

Back before I started on this game, I remember a friend of mine telling me how with the game he was working on, the last 10% was the hardest.

He was definitely right about that!

I found estimating the amount of time it would take to make Math Ninja extremely difficult. I feel like I’m pretty good at estimating how long it will take me to make applications, but for games it’s a completely different story.

I think the difficulty resides in the fact that a game is never really done. There’s always one more feature you could add, one more level you could include, or one more visual effect you could have to make things that much better.

So how do you know how long you’ll need to get it done? To me, that is an open question. I honestly had no idea, so just worked on it until I was happy for it, even though there are a bucket of features I could have potentially added.

But just getting to that point where it was ready to submit was definitely the hardest part. There were many times I was convinced it was “almost done”, and then found myself still working on it a week later!

Not to mention as the project dragged on, the more and more I wanted to “just be finished” and the more tired I was of working on the project. But yet it wasn’t quite ready and needed more polish, so there were many days of mentally forcing myself to finish up the remaining work to get it out the door.

So to make a game you need stamina to see it through – and you need to realize that no matter how much work you think it will be, it will probably be a lot more :]

Promo Codes!

If you’re interested in a promo code, I’ll give them out to the first 5 people to comment on this post. Just leave a comment with a valid email address and I’ll send one to you!

What Have You Learned?

Making my first iPhone game was one of the most fun and rewarding experiences I’ve ever had. I’m extremely happy with how it turned out and had such a great time developing it, and I feel like it taught me a lot of lessons along the way.

I’m really interested to hear others experiences developing games, and any useful lessons you may have learned. Please share below! :]


Category: iPhone

Tags: , ,

26 Comments

  1. renderplace (1 comments) says:

    Great post! A fully agree with 5)

    Keep on writing, congrats!

  2. Brandon (3 comments) says:

    Congrats Ray! I only found your blog a few days ago but I’ve really enjoyed your tutorials. I’m working on my own iPhone game and hoping to have it in the store this summer.

    I hope the game does well, keep up the great work!

  3. Brandon (3 comments) says:

    I’d love to hear more about your XML solution to level and game design. Any chance you could do a tutorial on that?

  4. George Sealy (3 comments) says:

    Congratulations on releasing your game Ray, and thanks for the write up – it’s an interesting read. And thank you for the site as a whole – plenty of good stuff here!

  5. Noah (3 comments) says:

    I would love a promo code – I’m working on my first game myself. Congratulations!

  6. Nate Potter (1 comments) says:

    Thanks for posting your experience coding a game. I’d love to see more articles on this, especially some of the nitty gritty solutions you’ve come up with.

  7. Ray Wenderlich (874 comments) says:

    Thanks for the comments all! That wraps up the promo giveaways at least for this post :]

    And yeah, the XML solution would make a great tutorial, thanks!

  8. Alex Caesar (3 comments) says:

    Great rant! I found it even more interesting since I am coding an Iphone game myself as we speak. However, being a future software engineer (ugrad) I think that most of the time it is better to just follow some somewhat strict coding conventions(you choose them) and then most additional features become easy to implement.

  9. chongasem (1 comments) says:

    I love your blog and content. I start my game but it the hard time for me. I search for make simple iPhone game and found your blog. Now I can make a Simple control for my game. Thanks for best article.

    ps. can i have some pro code thx!

  10. Sergej Karakcheyev (1 comments) says:

    Thank you for your tutorial. I want to make the game for my daughter. It should be little bit math app as well. Thanks so mach!

  11. mjshi (2 comments) says:

    Good post!

  12. Brandon (3 comments) says:

    Good luck with your game! Hope to see your game on the iTunes Top 10 Games soon.

  13. Mr ma (5 comments) says:

    Can you give your sample code to me, I will very happy to receive your code.

  14. Dad (44 comments) says:

    Hi Ray – nice blog post. Some good information – the tip about making game dynamics design & tuning easy is a good one. Geek and I definitely need to do that for the game we’re working on.

    Now comes the most challenging part – *marketing* your game. We’d love to hear what works (and what doesn’t) as you explore that side of the equation. I hope it goes well for you.

  15. Bhanu Prakash (2 comments) says:

    hay its very good,keep on posting, so freshers like me will learn more…
    congrats…..

  16. Bhanu Prakash (2 comments) says:

    can i have some promo code for building games from you..

  17. Ray Wenderlich (874 comments) says:

    Regarding promo codes: Unfortunately the 5 promo codes I had reserved to giveaway in this post are long gone! I will probably release more here for future games/apps I develop though so stay tuned :]

    @Dad: You are totally right, marketing is indeed the hardest part, and the part I have not figured out at all yet :P If/when I do I’ll be sure to share some tips!

  18. Joseph Neuman (8 comments) says:

    As for rewriting, I didn’t start fresh, but in my game, When Balls Drop, I has levels where a lot of the used the same code over and over again to create the objects in the way as the ball fell down. ( i know that had way to many commas sorry)

    What I ended up doing was creating files that had functions i could just call instead of the functions being at the bottom of each level’s file. It took quite some time to get everything to work right since i also had to delete them from the levels files and change how each function was called, but it makes expanding the game and making new updates so much easier!! It also lessened the size of the app (a little, not a lot).

    Now making updates to my app is so much easier.

  19. Ray Wenderlich (874 comments) says:

    @Joseph: Yeah, copying and pasting is so easy at first, but then comes back to bite you later ;]

    There’s a rule in computer science called DRY: “Don’t Repeat Yourself.” The more you factor common code into functions, the easier maintenance is – since you just have to fix any bugs or make any changes in a single place! :]

    How are things going with you – you working on anything new lately?

  20. Joseph Neuman (8 comments) says:

    Yes, it makes life a lot easier to not repeat yourself.

    Well I just submitted a huge update for When Balls Drop to Apple, and will work on updates after that.

    I just started (as you can probably tell) a new game that will be Universal for ipad/iphone that after about a day of work is in pretty good working condition. It shocks me how fast I am working with cocos2d/box2d now. I run into some issues (as you know) but for the most part and pretty good with things.

    I’m working with animations in my new game and with box2d on the animations as well.

    now I just have to take the time to take a good look at you Harder Enemies tutorial and figure out how to give HP to enemies and the such.

    Any new games for you being made? or updates on math ninja?

  21. Ray Wenderlich (874 comments) says:

    @Joseph: Yeah, I have the same feeling – after finishing a game and getting it out the door, I feel like I can get things done much more quickly and efficiently.

    Yep, I’m working on a new project myself! It’s not exactly a game… but it does involve Cocos2D! I’ll be posting about it in the upcoming weeks at razeware.com.

  22. Joseph Neuman (8 comments) says:

    @Ray: can’t wait to see it! :)

    i’m waiting to read your tiled tutorial until the second is out so i can go straight through them both. my buddy has an idea for a rpg ill code and he will graphic. soo keep the tutorials coming :)

  23. iDev_Asad (1 comments) says:

    can you please send me promo codes of your game/games.

    thanks

  24. Ray Wenderlich (874 comments) says:

    @iDev_Asad: Sorry the promo codes are long gone!

  25. Amsath (2 comments) says:

    hi ray i want promo codes to work…..can you please send that to me

  26. Ray Wenderlich (874 comments) says:

    @Amsath: Unfortunately, as I’ve noted above the promo codes are long gone now!

I'd love to hear your thoughts!