iPhone Game Programming: CoreAnimation vs. OpenGL ES
I saw an interesting question being asked by an aspiring iPhone game developer, "Should I use CoreAnimation or OpenGL ES?".
Simple answer:
Core Animation is fine for games where performance is not critical, and for new programmers will likely be easy to use, OpenGL is needed for anything else.
Long Answer:
Core Animation utilizes OpenGL ES, it is high level, and in my testing works fine in situations where performance is critical.
OpenGL ES is an open standard that is used on a growing number of devices created by a wide variety of companies, and because CoreAnimation is a higher level framework built atop OpenGL ES it cannot provide nearly the same performance.
My opinion is that Core Animation is likely the appropriate choice for games where performance is not critical such as simon says type games, card games, and trivia games. Some might argue that OpenGL ES is easier to use, and it likely is if you’ve studied say.. DirectX.. but Core Animation (and Quartz 2D for that matter) is much easier to do simple effects in, and can be used with existing UIViews.
OpenGL ES is your choice for performance critical games. Which is essentially anything but simple mostly static games like the ones mentioned I above such as first person shooters, flight simulators and the like. You also get the added benefit of potentially being able to port your games to a device other than the iPhone, and there is alot of existing game code in OpenGL that can be converted the other way. That being said for simple, static games for a newcomer to graphics programming my choice would be Core Animation although if you can wrap your head around the tutorials and frameworks on my OpenGL ES resources page OpenGL ES may be for you.
I hope this provides answer for anyone trying to decide whether they should program in OpenGL ES, any opinions from those who have done more with Core Animation than I have would be greatly appreciated.
I find OpenGL ES easier to learn than Core Animation
nice post
something i found was this:
http://www.sunsetlakesoftware.com/2009/01/13/op...
apparenlty the author was actually able to get better performance using coreanimation because it was easier to handle the user's touches
I'm the author of the linked post on optimizing OpenGL ES via Core Animation. The gist of that post simply is that Apple provides some very nice convenience methods for dealing with Core Animation, and because Core Animation is layered upon OpenGL ES you can use some of these functions for improving your interaction with OpenGL ES. In this case, I was maintaining a copy of the OpenGL model view matrix as a CATransform3D, manipulating it in code, then pushing it back to OpenGL. This cut out a number of expensive operations where you had to read the state of the OpenGL model view matrix to manipulate it, leading to a significant performance boost and cleaner code.
Overall, it has been my suggestion to those doing 2-D work to look at Core Animation first, before going to OpenGL. I've worked with both, and greatly prefer Core Animation to OpenGL ES. Apple has abstracted away a huge amount of the low-level procedural code within CALayer, CAAnimations, and the like. As far as performance goes, on the original iPhone, I measured that you can animate up to 50 translucent layers at 60 FPS (100 at 30 FPS). The biggest problem people have when they first come to Core Animation is they try to micromanage it and update positions of layers every animation frame. You have to learn to trust the design of the framework, lay out animations ahead of time, and let the framework do the heavy lifting for you. My latest application, Pi Cubed, has an interface entirely designed using Core Animation, something that would have been impractical to do using pure OpenGL. The new open-source graphing framework, Core Plot, is also entirely constructed using Core Animation.
That said, OpenGL ES is necessary if you want to do pure 3-D work, if you need to push beyond 50 moving objects at 60 FPS, or if you want to craft a cross-platform graphics rendering engine. Just be warned that OpenGL code is nowhere near as easy to manage or maintain as its Core Animation equivalent would be.
Thankyou for clearing that up Brad. I was very impressed by the speed when using Core Animation, from reading about how you “must use OpenGL ES” I thought things would run at a crawl, but was very impressed by both the spead, and the ease of Core Animation. I hadn't done any benchmarks so it is very good to know that 50 translucent layers were handled.