tags:

views:

500

answers:

2

I am using about 20 UIImageView of small airplane images (50x50 pixels) doing simple animation on the iPhone screen. The animation is done by shifting the UIImageView center property at timer interval.

[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES]

What is the best practice: create one NSTimer and loop the 20 UIImageView to set the center property when timer fired? Or should I just create one NSTimer per UIImageView object? Is NSTimer resource expensive? Thanks

+1  A: 

you could try both and use the built in profiling tools that ship with Xcode to gauge resource usage.

NoCarrier
+3  A: 

I don't think it's that resource intensive, but common sense would seem to dictate that using 1 timer is probably better than 20.

Looks like your timer is set to fire 100 times per second, which seems a bit excessive. Do you animate each sprite at every timer firing? Might want to try firing 20-30 times per second instead (or maybe even less).

You might want to look into the built in view animation functions as well. Seems like they would probably work very well for what you are doing.

Eric Petroelje
At at rate, I could imagine that the Objective-C overhead can be quite expensive.
Georg
Regarding firing rate: LCD's generally refresh at 60 Hz, so trying to animate more frequently than that is in fact excessive.
Daniel Dickison