1

I have a CAEmitterCell :

CAEmitterCell * spriteCell = [CAEmitterCell emitterCell];  
spriteCell.contents = (id) [[UIImage imageNamed:@"emitterSprite.png"] CGImage];

I would like the sprite to be an animated png sequence (or so) instead of a single image.

The only technique I know makes use of an UIImageView :

   NSMutableArray *animatedImagesArray = [NSMutableArray new];
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(...)];
    for (int i = 1; i <= 10; i++)
    {[animatedImagesArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"sequenceNo-%d%@", i, @".png"]]];}
    imageView.animationImages = animatedImagesArray;
    [view addSubview:imageView];

CAEmitterCell.contents doesn't seem to accept UIImageView. Is there a way to achieve this ?

kursus
  • 1,396
  • 3
  • 19
  • 35
  • I don't think so. What is the animation you want? Is it something beyond the simple rotation, color, etc, that the emitter supports? – i_am_jorf May 02 '15 at 03:56
  • Yes the animation is not reproducible with standard transforms. Do you know any alternatives ? – kursus May 02 '15 at 10:27

1 Answers1

2

For reasons of performance in the operating system what you are trying to do is not possible. If you have simple transformations like rotation, scale, colour tint you can edit those values in the properties of your the CAEmitterCell. If you require a more complex animation you will need to use a custom emitter that can handle UIImageViews. But be mindful of the performance implications.

Danny Bravo
  • 4,534
  • 1
  • 25
  • 43
  • Do you have any advice on how to find/create a "custom emitter that can handle UIImageViews" ? Thanks – kursus May 02 '15 at 10:27
  • Not at the top of my head, but maybe you could try subclassing CAEmitterCell, add a UIImageView property to it, have a CADisplayLink tell you when your screen has refreshed and then use that call to check what image the UIImageView is using and update the value of contents passing the right CGImageRef (but only update if the image changes). Hope this helps! – Danny Bravo May 02 '15 at 12:01
  • That's kind of an idea but I suspect some frames would be skipped ? Anyway if you're interested I will set a bounty on this question when I can. – kursus May 02 '15 at 12:46