开发者

sprite sheet animation in cocoa

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 a CAKeyframeAnimation to animate the layer's contentsRect on 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 frameSize or you won't get a working animation.

One side-note: I wanted to animate my sprites' movement by hand, so I set the position key to a null animation action in -[SpriteLayer init]. You may want to remove that line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜