I am testing an animated method for a magazine as a media oriented application. My goal
- smooth animation of hundreds of sprites
- with video playback
- and a standard user interface screen on an animation screen.
I am considering Core Animation or OpenGL.
OpenGL is definitely faster, but integration of video playback in GL sprites is not yet possible, as I know. (video function required for texture)
So I'm digging Core Animation. But the performance was too bad. I tried a simple gravity simulation with 256 of sprites with 11x10px bitmaps. And I only got about
- 10 fps
- 5% device usage
- 5% rendering profitability
- 0% use of tiler.
The bottleneck is obviously in the CPU code.
, CA GL , . . CA , , , .
. . , . . , . , .
?
: ( CADisplayLink):
- (void)tick
{
[CATransaction begin];
[CATransaction setAnimationDuration:0.0f];
CGRect bounds = [hostLayer bounds];
CGFloat gravity = +9.8f * 0.1f;
for (TestParticleSprite *tspr in spriteLayers)
{
CGSize mtn = [tspr motion];
CGPoint ctr = [tspr position];
mtn.height += gravity;
ctr.x += mtn.width;
ctr.y += mtn.height;
CGFloat over = ctr.y - bounds.size.height;
if (over > 0.0f)
{
ctr.y = bounds.size.height - over;
mtn.height *= -1.0f;
}
[tspr setMotion:mtn];
[tspr setPosition:ctr];
[tspr removeAllAnimations];
}
[CATransaction commit];
}