I’m working on a simple iPad app which has an animation of 12 separate images using CAKeyFrameAnimation.
Just wondering what would be the simplest way to go with one sprite sheet and a plist file which describes that sprite instead of loading 12 separate images?
What I did was to load the spritesheet as a single image, load up the plist into bounds-normalized
CGRects, then use aCAKeyframeAnimationto animate the layer’scontentsRecton the@"sprite-animation"key.This gist contains the class I wrote. It doesn’t have a method to load up a plist of animation names, frame indices, and timings, but it would be easy enough to write one. The main gotcha is that you must be sure to set the layer’s
frameSizeor you won’t get a working animation.One side-note: I wanted to animate my sprites’ movement by hand, so I set the
positionkey to a null animation action in-[SpriteLayer init]. You may want to remove that line.