I just want to animate snowflakes/other objects in the background falling down. I know a couple of ways to do this, but am really looking for the most efficient solution. I could use this doing a UIView block animation. I would have it start at the top of the screen and animate to the bottom of the screen over a period of time, then on completion start it again at the top. Is that a good way to do it? I'm looking for efficiency here.
-
1You might want to use layers directly instead of using lots of little views. It would be much more efficient. – sudo rm -rf Nov 10 '11 at 16:17
-
1You're probably looking for a particle system to do this, in which case the answers to the questions [iPhone. Particle system performance](http://stackoverflow.com/questions/2538248/iphone-particle-system-performance) and [Drawing particles](http://stackoverflow.com/questions/5407046/drawing-particles) provide a few different ways of approaching this. – Brad Larson Nov 10 '11 at 16:19
-
sudo rm rf - are you indicating that I should use the layer on a view (the canvas I suppose) and then draw multiple items onto that layer? – spentak Nov 10 '11 at 22:10
-
Yes I suppose that's what I was saying. However, I haven't done it myself and I might just be spouting something off that might not be the the best idea. I do know that layers are much more efficient for animation and drawing when compared to views, but I'm not sure how well they would do when you have a huge number of them, like the situation you're describing. On a slightly different note, have you looked into Cocos2D for a particle emitter? It's free, and hooks directly into OpenGL. See a particle emitter that looks like what you're looking for here: http://cli.gs/cocos2d-particle-snow – sudo rm -rf Nov 11 '11 at 02:16
3 Answers
You want a CAEmitterLayer! http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CAEmitterLayer_class/Reference/Reference.html
It's iOS 5 only though.

- 14,691
- 7
- 40
- 60
It's only $8 for 71Squared's emitter. You can pretty much copy and paste the code. But it's biggest advantage is configuring the particles exactly the way you want, which can be more time-consuming than figuring out how to make particles in the first place.

- 8,710
- 10
- 47
- 72
As previously answered by Randall and Javy you want a CAEmitterLayer and you probably want to configure it with a live preview like Particle Designer, which doesnt work with CAEmitterLayer.
For CAEmitterLayer you could use Particle Playground (Mac App Store) to configure your emitter on your mac in a simulator and the export it as code ready for integration in your project. PP is quite similar to Particle Designer.

- 426
- 4
- 9