[Performance] PNG sequence animation with SpriteKit and CoreAnimation

Hey, all

I am still pretty new to SpriteKit and I want to understand the benefit of using SpriteKit when having a sequence of PNG files.

I have conduct a comparison animations between SpriteKit and CoreAnimation. and the result I found is that CoreAnimation is outperformance with SpriteKit with Sprite Sheet.


To setup, I have a create a 25 frame PNG files(label them from abc_0 to abc_24). I put one copy inside my.atlas direcotry and one copy inside the asset catalog.


In the SpriteKit version, I load the atlas and create 25 textures from it. Create SKAction with animateWithTextures:timePerFrame:resize:restore:. I use 0.0017s as per frame. And then I runAction with my Node.

I measure the total time from loading atlas to runAction. It tooks about 0.05 sec to performance all these commands on average.


In the CoreAnimation, I load the image via [UIImage imageWithName:@"abc_*"] which will return a set of image. And then I convert all the UIImage object into CGImage and put then into a CAKeyframeAnimation and add this animation to the layer.

I measure the total time from loading the image to addAnimation:forKey:. It tooks about 0.01 sec to performance all these commands on average.


Thus, my conclusion, CoreAnimation has a better performance than SpriteKit in handling the PNG sequence animation.

My question: Do I miss anything? Is there any reason that I might want to use SpriteKit instead of CoreAnimation?

No. Don't think you've missed anything.


In many ways, Sprite Kit looks like Core Animation wrapped in a game loop and other bits and pieces.


Now that Core Animation is Metal backed it's probably best to use it whenever you can.

[Performance] PNG sequence animation with SpriteKit and CoreAnimation
 
 
Q