The easiest way is to use Core Animation layers to create sprite animations:
Make a "multi-cell" strip of the image (maybe PNG or JPG) of all the different movements for the sprite. Make each cell a fixed height or width.
Put the image in a UIImageView.
Take the CALayer in the view and set the contentsRect property of this layer. This acts as a cropping rectangle for the sprite. To animate a sprite, all you have to do is move the contentsRect to the next cell position in the image strip.
Something like this will do it (if you have already calculated newSpritePosition.
[CATransaction begin]; [CATransaction setDisableActions:YES]; spriteLayer.contentsRect = newSpritePosition; [CATransaction commit];
(If you do not execute the second line, then you will get a default slide animation instead of "going" to the next state.)
With this technique, you can rotate through all sprite frames - like flip books. CALAyer operations are optimized, so you should get a pretty fast frame rate. You can set the animationDidStop completion handler to go to the next sprite or loop state back to the start frame.
source share