For a real time game, Should I use core animation or redraw images frequently?
Say I have to move a image across the screen according to user input....
- Use core animation periodically to animate the movement in small chunks.
- Redraw the image frequently at different locations.
If there is no clear answer, what are the advantages of using each method?
CoreAnimation is not generally made for game programming, and doesn't have the performance characteristics that it generally takes to make a real, playable game. You may be able to make a very basic game very easily with CoreAnimation, but it's likely that at some point you will run into these performance limitations, and at that point you will probably need to rewrite your codebase using a real gaming engine.
To be clear, CoreAnimation is amazing and is ideally suited to the task for which it was created, which is application UI development. But it doesn't take much in terms of sprite count and size before you hit the performance wall when using it in a game. I say this because I have tried it.
My recommendation is to use one of the easy, off-the-shelf gaming engines available on iOS, like Cocos2D, to write your game. It's easy enough for a relative beginner, but is more suited to game development both in terms of performance characteristics and API.
Core Animation was made for you. The whole point of Core Animation is move images around the screen really fast. Core Animation works even better when the actual content of the images don't change.
EDIT: Redrawing the image is less preferable because
- If you redraw the image with Quartz and override drawRect: you will be relying the CPU to draw all of those images
- If you use OpenGL and accelerate your app with the GPU--using it only to draw images onto the screen and move them around--you have replicated the functionality of Core Animation
- Core Animation has animation primitives built-in