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 开发者_如何学JAVAuse?
- 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.
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.
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.
精彩评论