Any suggestion for an optimization method for Core Animation apps?

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)
  {
   // Hit the ground!
   ctr.y  = bounds.size.height - over;  // Bounce.
   mtn.height *= -1.0f;       // Bounce.
//   mtn.width *= 0.95f;       // Lose energy.
//   mtn.height *= 0.95f;       // Lose energy.
  }

  [tspr setMotion:mtn];
  [tspr setPosition:ctr];
  [tspr removeAllAnimations];

//  // Tried explicit animation, but it was unable to make it work.
//  CATransform3D  t  = CATransform3DMakeTranslation(ctr.x, ctr.y, 0.0f);
//  CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform"];
//  [anim setAdditive:NO];
//  [anim setCumulative:NO];
////  [anim setFromValue:[NSValue valueWithCATransform3D:t]];
//  [anim setToValue:[NSValue valueWithCATransform3D:t]];
//  [tspr addAnimation:anim forKey:nil];
 }

 [CATransaction commit];
}
+3
1

Shark ( CHUD) , - , .

+1

Source: https://habr.com/ru/post/1776070/


All Articles