views:

342

answers:

2

I want to make some simple 2d games/clones (for Mac), but I have a few questions:

  • Should I use Quartz 2d or OpenGL (I don't plan to try 3d anytime soon)
  • There seems to be a lot of typedef'd things like CGFloat/GLfloat, which should I use?
  • Should I use Objective-C for the game too (classes) or just C? (I assume I'll use Objective-C and Cocoa for window and views.)
  • Is it fine to redraw the entire view each time? I don't really understand how the NSView's -drawRect dirtyRect parameter works, how does it know what I want to update?
  • Are there any good tutorials for this?

Thanks.

+2  A: 

Quartz or Core Animation vs. OpenGL really depends what you're trying to do. If you want simple drawing and animation, use Quartz or CA. If you want fast/powerful games, use OpenGL. Eventually I'd suggest learning both.

For the typedef'd things, use whichever is meant for the specific system you're using. For Quartz/CA/CG, use CGFloat. For OpenGL, use GLfloat.

Objective-C vs. C also depends on the speed you want. Objective-C adds a little bit of overhead but will (obviously) let you create much more object-oriented games. I'd suggest using Objective-C if you use Quartz and Core Animation, and either Obj-C or C if using OpenGL. However, if you're doing this on a Mac (e.g. not for iPhone), you probably won't see much difference unless you're doing complex fast drawing.

I'm not entirely sure about drawRect, but this question has some information which may answer that question for you.

For an intro to Quartz, I'd recommend this tutorial, and I've always heard the NeHe tutorials recommended for OpenGL.

jtbandes
Thanks for the quick reply! Right now I just trying to make a boncjng ball animation with simulated gavity, but I want to try a snake clone next, and ultimately head for more complex things. And yes, this is not for the iPhone. What can you actually do with core animation? And am I right that OpenGL is more moving objects while quartz is more painting shapes?
Mk12
Core Animation lets you do movement and animation really easily. Quartz is for drawing. I believe they can be combined. OpenGL is I guess for moving objects, scenes, etc.See this guide: http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/CoreAnimation_guide/Introduction/Introduction.html
jtbandes
If I did most of it in C it would probably be a lot easier to port to Windows though, right?
Mk12
I suppose so, but the code would be nastier. If you want it to be portable, OpenGL is probably the easiest.
jtbandes
I meant use C with OpenGL.. OpenGL is in C, not Objective-C. I meant only use Objective-C for cocoa application, window and view, and then plain C for the game code (using OpenGL).
Mk12
I don't see any reason why you couldn't use Objective-C on windows.
Breton
Yes, you could definitely do the application in Obj-C and the drawing/game stuff in C/OpenGL. Breton, you could, it's just not very common and would feel a little bit strange to me.
jtbandes
A: 

If you use SDL with either Cairo or OpenGL, you get virtually the same programming model, but you get cross platform compatibility virtually for free. You should even be able to continue using objective C for the bulk of the game, if you want.

How graphically intensive do you want to get? Cairo will probably be easier to just get going with for 2D.

Breton