Beginners iPhone Action Game Tutorial: Source Code

A few weeks ago I posted a short video similar to this one:

UPDATE: Tutorial Has been posted!

I’ve been asked since then when I would come out with the tutorial.   I was finally able to get around to completing the source file, and I’ve added line by line (well pretty close) comments in plain english to make it easier to follow.

The above video utilizes the exact source code from this tutorial running in the iPhone simulator.

Following the suggestions of a friend of mine who is just starting to learn this I’ve used as few methods as possible, and made extensive use of autorelease objects to make the flow easier to follow for beginners.

The tutorial features:

  • Loading/Placing Images
  • Animation
  • Touch Events
  • Text
  • Sound Effects
  • Background Music
  • Buttons
  • Resetting The Game

Coming up next week I will be posting a more comprehensive tutorial, but I am posting the source code now.  If you look through this code and the comments you should be able to grasp what is going on, and I hope that the upcoming tutorial will fill in the gaps. Be sure to come back next week when the full tutorial is posted!

I recreated this from scratch using Sparrow Framework and Objective-C because in my findings it was easiest to follow for a beginner looking to create an action game.

Things could change a little as I haven’t really looked through it myself.. just quickly coded it and wrote line by line comments. If you open it up, and are wondering which files to look at to understand things go to the Game.h and Game.m files.. the app delegate files were created automatically with the Sparrow project and I didn’t comment those.

Update! I have modified the project to remove an error that occurred on some systems due to a recursive search being done in the project for already included files.  Please re-download if you encountered this problem.

You can download the source with music/sound effects here:
BalloonGameTutorial

Graphics are included so the example will run but are slightly different because I am using graphics similar to those in the video in my own game.

As far as licensing goes feel free to use this in your own apps, and if you do send me a message or post a comment about it, and I’ll mention it on this site. You may not use any portion of this project in your own tutorials, books, etc. (and definitely don’t submit it to a site buying tutorials.. you know who you are!) without permission.

Please be sure to check back next week when the entire tutorial is posted which will give you a much better idea of how to extend/use this source code and utilize the Sparrow Framework.

If you have any questions as to why I did something or have any suggestions for the tutorial then please post them below — it will help to make the final tutorial better.

Also, if you could share this post that would be great too and help motivate me to make more!

DeliciousTwitterTechnoratiFacebookLinkedInEmail
Tags: , , ,

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can send a Tweet to @maniacdev on Twitter or submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

  • Fdas

    Amazing dude, thanks!

  • http://twitter.com/edeNFed Eden Federman

    Wow, cant wait to the full tutorial

  • H4CK3R

    Great work thanks!!

  • Jeffthrower

    Are you going to be breaking this down to a line by line overview? I'm just getting started with this and have no other programing experience. I bought a couple of books, but they really didn't help.

  • http://maniacdev.com maniacdev

    That's the idea.. and if you take a look at the source I've got line-by-line comments in there.

    Which books did you read?

  • 9livesoftware

    I tried to build it but kept getting an error

    “Argument list too long: recursive header expansion failed at /Applications/Adobe Device Central CS5/Adobe Device Central CS5.app/Contents/Resources/LogTransportLaunch.app/Contents/Frameworks.”

  • http://maniacdev.com maniacdev

    Weird. can't help you there as it should have nothing to do with adobe.. unless device central messes around with xcode and the iphone simulator.

  • Jeffthrower

    I have read through Iphone apps for dummies. and another one but they both said that you really need to know objective c

  • http://maniacdev.com maniacdev

    I'll guess the other one is beginning iphone development or beginning iphone 3 development.. all those books are good, but some people seem to be misled by the “beginning” and “dummies” in the title that those books are for absolute beginner programmers which they are not.

    Are you looking to do learn this to build an app, pass a course, or gain employment?

  • http://www.sparrow-framework.org Daniel

    The problem you describe often occurs when your project references a “source tree” variable (Xcode – Preferences – Source Trees”) in the project or target build info, but the variable does not exist. I guess Xcode then tries to search your complete system (“/**”) for include files, and gives up after a certain number of directories — thus the weird error.

    I just had a look at the project, and indeed, it references the source tree variable SPARROW_SRC in the target info (build tab), which is not needed in this project, as Sparrow is included directly (not by project reference). To remove the error, just remove this reference.

    Maniac, you could remove this setting from the project for your final tutorial (or the download link). Thanks!!

  • Jeff Thrower

    I want to build an app, i don't think I could make a living, selling apps.

  • http://maniacdev.com maniacdev

    Thanks for the info Daniel. I removed that reference should be ok now. I guess this only causes a problem in isolated cases where xcode cannot open up a certain directory?

    Over 200 downloads only one person posted about the issue.

  • 9livesoftware

    thanx maniac and daniel it works fine now xD. haha i guess Im lucky number 1 :D

  • http://maniacdev.com maniacdev

    Thanks for telling me about it. There were probably some others that just didn't speak up.

  • Pingback: The Best Resources In iOS Development July 26th 2010 (For Week 07/17-07/23) | iPhone iOS 4 iPad SDK Development Tutorials, Programming Tips, News

  • Pingback: Update To Action Game Tutorial Source | iPhone iOS 4 iPad SDK Development Tutorials, Programming Tips, News

  • http://www.sparrow-framework.org Daniel

    You're welcome! I'm surprised that the problem did not pop up more often — perhaps some users downloaded Sparrow manually and followed its installation instructions before trying out the tutorial. In that case, they'd already have the variable defined.

    In my opinion, it's a bug of Xcode that it writes out this recursion error — a small warning that a non-existing source-variable is referenced would be much more useful!

    BTW, thanks for editing the project =)

  • Seepsoda

    Really impressive, thanks. I am new to iPhone development and got your balloon game running without a hitch – thanks! What a smooth intro into iPhone game writing. You and the clever guy at Sparrow are super heros!

    Thanks! Looking forward to the full tutorial, and thanks for allowing full use of the source.

    Keep it up ;-)

  • Sudhanshu

    Hi,
    This is really a great tutorial, I think this was the kind of tutorial I was looking for.

    Great work and THANX A LOT!!!!!!