Search code examples
iphoneiosopengl-escore-animation

Core Animation for Games FPS (iPhone)


I recently started learning OpenGL ES for iPhone Development, but several people on Stack Overflow mentioned that Core Animation with images is a lot easier than OpenGL (for 2D games). I read up on CA, and a website I found stated that Core Animation is mainly for making board games. Is this true?

The game I'm trying to make is similar to asteroids, so I found this to be useful: http://cocoawithlove.com/2009/02/asteroids-style-game-in-coreanimation.html However, most of us know that the Mac/iPhone Simulator is a whole different world than the actual iPhone device. So, bottom line: will Core Animation work for my needs? Will it be able to live up OpenGL ES's 60 FPS?


Solution

  • As with any performance-related question, the answer will depend on what you're trying to do and the hardware you're trying to do it on. As I report in my answer here, I was able to animate 50 moving translucent CALayers at 60 FPS on the original iPhone hardware using Core Animation. Currently shipping devices, like the iPhone 4, iPad, and particularly iPad 2 are much faster than this first generation of hardware.

    I'd recommend trying to port Matt's Mac Core Animation Asteroids example over to iOS as an exercise. As you say, you can't tell what the performance will be like until you run it on an actual device, so why not give it a try? Looking at what he does, it shouldn't be that hard to bring that example to iOS because much of the Core Animation code will remain the same.

    You might have gotten the "Core Animation is just for board games" impression from Jens Alfke's GeekGameBoard code, which does implement a board game system using Core Animation. Several people have based other applications off of this. That doesn't mean that Core Animation is only useful for that particular genre.

    Yes, OpenGL ES will give you the ability to extract that last bit of performance out of the hardware, but it will take a lot more code to do so if you don't leverage a framework like cocos2d. Core Animation can be very fast, if you use it properly, and is much easier to work with.