Game Programming for iPhone? Help with Cocoa and MVC.

Nibbie
Posts: 3
Joined: 2009.01
Post: #1
Hi guys,

I've been looking up and down the web trying to find a decent tutorial on how to start making games on Cocoa, specifically for the iPhone.

I am a relatively experienced programmer, my main languages are Java and C.

Let's say I wanted to create a very simple game, one that has a main window and that you could move a character left and right...

How would you set this up on Cocoa?
What classes would you use?
Would you create subclasses of let's say: UIView and UIAnimation or etc?
Would you use the Interface Builder at all?
What would be the Model the View and the Controller on a game?

Thanks,

Hopefully if my questions are too noob or too complicated to answer you can point me towards a tutorial I haven't yet found.

Holografix.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #2
It's unfortunate, but there isn't a tutorial on this that I've heard about yet. I've seen this question pop up so many times that I'm starting to consider writing one myself. At least since you already know C then things will be much easier for you.

For iPhone I wouldn't use Cocoa, and I wouldn't worry too much about MVC, I'd just use OpenGL and straight C. You have to use a small amount of Cocoa for a few things, but it's pretty minor.

An example to start with is Apple's OpenGL ES template for iPhone. Basically, the drawView method is where you do your game "loop" (if you can call it that). Then look at their GLSprite sample. Then try to find a copy of their old CrashLanding sample if you can find it.

I don't know where you can learn OpenGL ES either, unfortunately. Check out this OpenGL FAQ
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2009.01
Post: #3
AnotherJake,

Thanks for your reply!

As a matter of fact I have found the GLSprite sample and I have been going up and down the code understanding little bits of it. I can see now that I will need to read up on OpenGL before I continue any further...

The thing is that I want to start out simple by developing a 2d game, I was told that I should use OpenGL for this on the iPhone since it will be much faster. All I want to do (as in every other game) is to have various sprites running around the screen.

Am I barking up the wrong tree?

Thanks,

Holografix.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #4
Yes OpenGL is the best way to do it, although you *can* use CoreAnimation, which is plenty fast for a few sprites (a few dozen maybe?). One big advantage to CoreAnimation is that the timing and tweening is all handled automatically for you. One downside (among many) is that it isn't going to be able to grow with your needs as you create more games on iPhone, which means all that time you spent learning CoreAnimation could've been spent learning OpenGL ES in the first place.

Ultimately, the decision is up to you of course, but I would personally take the OpenGL ES route. I tried Core Animation first on iPhone (even though I already knew OpenGL) and have decided OpenGL/C is the way to go with iPhone.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2009.01
Post: #5
Yeah definitely going the OpenGL way! But damn its complicated... I've found this framework online called "cocos2d" I think it is very promising, in a few minutes I got some basics up, like a menu screen that allowed me to click (touch) on start and an image for a background that sort of thing...

Thanks a lot for your tips I'm gonna have a deeper look at this cocos2d and I'll keep reading up on OpenGL, I plan on writing a guide once I get familiar with it all!
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #6
Yes, there are varying levels of complexity to OpenGL, depending on how you use it. You're at the hardest part, the initial learning curve, which is notoriously steep.
Quote this message in a reply
Member
Posts: 75
Joined: 2009.01
Post: #7
Oh man!
I am SO confused now...
I've been doing so much research on just how to start making games for the iTouch since flash was a nono, and my result was:

ObjC in Xcode.

Now i'm reading this and all I need are apparently OpenGL ES and C (not ObjC).

Clarification please =]
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #8
Yes, it's confusing to get started. As you posted in your other thread, you're onto it:

- C
- then little bit of ObjC for system API calls
- then OpenGL

Yes, programming is done in Xcode.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Upcoming Multiplatform Game Programming Book for Beginners JazonYamamoto 3 1,404 Apr 14, 2014 05:55 PM
Last Post: JustinFic
  Animator with interest in programming for iPhone; where to start? Taricktds 2 4,231 Jan 7, 2011 02:48 PM
Last Post: johncmurphy
  Game engines with object programming JonnyThunder 3 8,186 Aug 16, 2010 10:42 AM
Last Post: SethWillits
  free mac game programming book jaked 4 6,757 Jun 8, 2009 12:48 AM
Last Post: SethWillits
  Game Programming Tutorial markvw 0 4,293 Jan 27, 2009 05:10 AM
Last Post: markvw