views:

629

answers:

3

I'm looking to create a snowfall effect on the iPhone and I'm looking for advice as to how to best implement this. I've planned to use a png image as the sprite.

+1  A: 

You could either dynamically create a bunch of UIImageViews and animate their positions in a loop (or possibly with core animation), or could draw the images to a CoreGraphics layer, and update that with a loop.

The third option would be an OpenGL solution, but I am pretty sure that you are not asking about that. Besides, OpenGL content over UIKit view will not perform very well.

Squeegy
Do you have time to throw a little snippet of how you might implement this? I'm really new to Cocoa and could use a good implementation of UIImageViews to reference. Thanks.
Rob Sawyer
That was kinda fun: http://gist.github.com/66065 THere is a whole lot it doesn't do, and I have no idea if it even compiles. But my approach should be pretty clear. Also, I didn't write a dealloc method, so you would still need to do that. And may CA can animate it smoother than this.
Squeegy
A: 

If you have a series of keyframe animations as PNGs I woudl suggest using UIImageView's animation methods. UIImageView itself supports looping animations through a series of UIImages and you can use UIKit built in animation to animate the positions.

It is not going to be very efficient though. For high performance I think you are going to have to drop down to OpenGL which is a lot more learning.

I'd also suggest looking at Matt Gallagherts Quartzeroids. A game using CoreAnimation as the renderer.

Roger Nolan
+4  A: 

This sounds like a good use for CALayers. Take a look at Scott Stevenson's NanoLife example. It's for the Mac rather than the iPhone, but it's a good example of using Core Animation for particles.

Chuck
Thanks, I'll take a look.
Rob Sawyer