R – Using Core Animation, is there a way to group animations for several CALayers

animationcore-animation

I have a situation where I have many CALayers which animate in a "turn based" fashion. I animate the position on each of those CALayers, but they have the exact same duration. Once all of those CALayers are finished animating, a new "turn" is initiated and they animate changing positions again.

The whole idea is that with a linear interpolation between positions, and at a constant speed, a turn based transition between state to state looks like a real time animation. This, however, is hard to achieve with many different CALayers.

CAAnimationGroup is used to group together animations on a single CALayer. But I was wondering, is there a simple solution to group animations, which are supposed to have the same durations, on several CALayers together?

Edited to include a reply to Kevin Ballard's question

My problem lies in this. I'm creating animations for each of my CALayers, then putting
those in an NSArray. Once I get the callback that the individual animation has ended, I remove it form the NSArray. Once it's empty, I again create animations for them all.

With more than a few layers, there's a noticeable delay between where all of the animations finished and the new ones start.

I imagine that if I could group all of these animations into a single one, a lot more layers could be animated without a delay between animations. Thereby not ruining the illusions of a contiguous animation.

Best Answer

If you attach animations to multiple CALayers within a single method, they will all commence at (effectively) the same time. I use this approach in a puzzle game with dropping balls, at the end of the animations I attach the next stage of the animation to any ball that needs further animation.

I'm animating upto 60 CALayers at a time and not experiencing any delays between stages of the animation, but I don't cache the animations in an array of any sort, I'm not sure of thge overhead you have there.

My animations are relatively simple, and created and attached to each CALayer on the fly. My sprites are 60px square and use a couple dozen possible images to represent their content.

In some cases there are multiply animations that I can create with different starting times(using beginTime), I bundle them up with a CAAnimationGroup - but you may not be able to precalculate subsequent animations.

Related Topic